I have the following pieces of code and text. I want the file to be read and when it "detects" a value of say '0.12', it prints that element ('s') as well as the subsequent elements in that line (i.e. 'Single' and '220'). So far, its not printing anything.
Driver/Test:
import java.io.*;
import java.util.*;
public class BondDriver
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner obj4 = new Scanner(System.in);
System.out.println("Please type a bond length: ");
String value2 = obj4.nextLine();
List<String> list = new ArrayList<String>();
Energy obj = new Energy(value2);
File obj3 = new File("chemistry.txt");
Scanner obj2 = new Scanner(obj3);
while(obj2.hasNextLine())
{
String value = obj2.nextLine();
String str[] = value.split(" ");
list = Arrays.asList(str);
for(String s: list)
{
if(s == value2)
{
System.out.println(s);
}
}
}
}
}
Class:
public class Bond extends Energy
{
public Bond(String length)
{
super(length);
}
}
Class:
public class Energy
{
private String length;
public Energy(String length)
{
this.length = length;
}
}
Text ("chemistry.txt"):
0.11 Single 370
0.15 Double 680
0.14 Triple 890
0.14 Single 435
0.18 Single 305
0.10 Single 360
0.15 Single 450
0.16 Single 340
0.10 Single 500
0.12 Single 220
0.14 Single 375
0.074 Single 430