aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 4240
    
    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: 36465
    
  15
And why are you using floats?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

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: 36465
    
  15
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: 36465
    
  15
You’re welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is trim not working?
 
Similar Threads
Write into an XL sheet from java prg
abstract class
Creating Dialogs
getting Exception in thread "main" java lang Unsupported Class Version Error
plz tell me