Solved

Why this not working !!!

Posted on 2004-09-08
6
225 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
corduroy9 earned 50 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate insert example 13 39
by zero exception 10 70
mysql jsp example issue 32 74
activeMQ Queue Messages Enqueued and Messages Dequeued 1 39
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

726 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