• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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
0
nStudent
Asked:
nStudent
1 Solution
 
objectsCommented:
shouldn't be any difference
0
 
zzynxSoftware engineerCommented:
>> this line does not work
You mean?
0
 
Nick_72Commented:
There's no difference between those two examples.
Second should work too, perhaps the accountId was not 12345 when you tested the second one? ;)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
corduroy9Commented:
you may have to cast it as a string before the trim, like...

if(  ((String)(object.getAccountId())).trim().equals("12345"))
0
 
corduroy9Commented:
or before the equals()
0
 
sgalzinCommented:
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now