Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using substring, help

Status
Not open for further replies.

papaboy2

MIS
Jan 28, 2003
52
0
0
PH
hi, why is it that i can't use if statement on my WholeString Variable? but when i use Println it contains the "[" value?, line is a string variable where value is from input.readline() statement, i can't execute the statement inside if statement, thank you very much

String MySam;
MySam = line;
WholeString = MySam.substring(0,1);
System.out.println(WholeString);
if (WholeString == "[") {
System.out.println("Execute this");
}
 
The operator "==" compares ObjectA with ObjectB on a memory level - ie do the objects reside at the same address in memory. It does not compare for string equality - its not a scripting language, nor are there overloaded operators like C++ !!!

You mean :

if (WholeString.equals("[")) {

However, if you used this :

char mychar = MySam.charAt(0);
if (mychar == '[') {

}

then you can use that because you are comparing primitive data types, not objects.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top