Click to See Complete Forum and Search --> : need help....


ras_pari
September 25th, 2009, 05:25 AM
String b=1;
I have to ask a question .....that how to compare a string array and a string variable...I am using equals()...but that is not working.....My code is as follows..
for(int j=0; j< splits.length ;j++){


if (splits[j].equals(b)) {
System.out.println("The strings are equal.");
} else {
System.out.println("The strings are unequal.");
}


}
Here splits is a string array...b is a string variable......I want to compare this string variable and split array....

holestary
September 25th, 2009, 05:37 AM
please post your full code..we can see what u wanted and did..

dlorde
September 25th, 2009, 06:34 AM
I am using equals()...but that is not working....
The equals method is the correct way to compare the value of two Strings for equality. The code you posted will compare every String in the array with the target String (although String b=1; is clearly wrong).

Have you printed out the contents of the array and the target String to check their values?

The person who says it cannot be done should not interrupt the person doing it...
Chinese proverb