?
Solved

Why this not working !!!

Posted on 2004-09-08
6
Medium Priority
?
229 Views
Last Modified: 2010-03-31
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
Comment
Question by:nStudent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12005298
shouldn't be any difference
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12005306
>> this line does not work
You mean?
0
 
LVL 9

Expert Comment

by:Nick_72
ID: 12005315
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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 2

Accepted Solution

by:
corduroy9 earned 150 total points
ID: 12005475
you may have to cast it as a string before the trim, like...

if(  ((String)(object.getAccountId())).trim().equals("12345"))
0
 
LVL 2

Expert Comment

by:corduroy9
ID: 12005481
or before the equals()
0
 
LVL 4

Expert Comment

by:sgalzin
ID: 12005506
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question