Jay Roy
asked on
java trim() issue
hi guys
In my code i have
Thanks
In my code i have
DetailVO obj = detailIterator.next();
String name = obj.getName();
String trimmedName = obj.getName().trim();
System.out.println("name>>>"+name); //prints MICHEL, JEFF
System.out.println("trimmedName>>>"+trimmedName); //prints MICHEL, JEFF
Any idea why trimmedName doesnt show trimmed spaces?Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You would have to do something like this:
Construct a StringBuilder
Iterate over each character in the string
Add it to the StringBuilder if Character.isWhitespace() returns false
ASKER
well, how about a simple string.replace(" ","").trim()
Does using StringBuilder give me any performance benefit ?
thanks.
Does using StringBuilder give me any performance benefit ?
thanks.
String.replace() will likely do more work than using the StringBuilder yourself, but you're right that it should give you the result you want.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thx