This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Why is trim not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why is trim not working?" Watch "Why is trim not working?" New topic
Author

Why is trim not working?

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi folks ,
Im trying to trim a field(remove all whitespaces , in the following manner)

but i get the following exception.

Any idea why im getting the exception?


Learning and Learning!-- Java all the way!
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4339
    
    7

Switch (stractualflow != "") to !stractualflow.equals(""), and see if that helps. Remember you should never use == and != to compare Strings.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37902
    
  22
And why are you using floats?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

With this code you can drop the check for stractualflow != null, because if it were null the trimming would have already thrown a NullPointerException.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37902
    
  22
And also put spaces between tokens. It is much easier to read if (sfractualValue != null) ... than if(sfractualValue!=null) ...
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Campbell Ritchie wrote:And also put spaces between tokens. It is much easier to read if (sfractualValue != null) ... than if(sfractualValue!=null) ...


And it is MUCH easier to read it the positive way...

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Thanks a lot guys !
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37902
    
  22
You’re welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why is trim not working?
 
Similar Threads
getting Exception in thread "main" java lang Unsupported Class Version Error
plz tell me
Write into an XL sheet from java prg
abstract class
Creating Dialogs