I have a problem comparing strings..please help
in
Programming Questions
•
8 months ago
I tried a simple program like below to just for test :
- String a = "a";
- String b = "a";
- if(a == b){
- print(true);
- }
and its working. But when i tried to read a String from a text file and compare it, it doesnt work :
- String read[] = loadStrings("locationOfTheFile"); //let say that we have 3 lines each with 2 columns,
- //the String I would like to compare is at the
- //1st column
- String answer = "why"; //compare with this
- for(int i=0; i<read.length; i++){
- if( why == splitTokens(read[i])[0]){
- println(true);
- } else {
- println(false);
- }
- }
I got all 3 lines as false but its actually got the same words "why"..could someone help??
1