Link to home
Start Free TrialLog in
Avatar of nStudent
nStudent

asked on

Why this not working !!!

Hello,

Question::
method that work...........
String str=object.getAccountId().trim(); //this question is on the line
if(str.equals("12345"))
{
  System.out.print("12345");
}
else
{
 System.out.print("Error");
}

method that doesn't work......
if(object.getAccountId().trim().equals("12345")) // this line does not work why this happen????
 System.out.print("12345");
else
 System.out.print("error");

Thk U
From newbie
Avatar of Mick Barry
Mick Barry
Flag of Australia image

shouldn't be any difference
>> this line does not work
You mean?
Avatar of Nick_72
Nick_72

There's no difference between those two examples.
Second should work too, perhaps the accountId was not 12345 when you tested the second one? ;)
ASKER CERTIFIED SOLUTION
Avatar of corduroy9
corduroy9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or before the equals()
hi,

depending on what getAccountId returns :

/*** returns object : ***/
if (object.getAccountId().toString().trim().equals("12345"))
 System.out.print("12345");
else
 System.out.print("error");


/*** returns int or similar : ***/
if ((new Integer(object.getAccountId())).toString().trim().equals("12345"))
 System.out.print("12345");
else
 System.out.print("error");


is any of these better ?

stephane.