Java trim string array 

Joined:
04/09/2007
Posts:
727

July 14, 2011 11:50:28    Last update: July 14, 2011 11:50:28
This is not to make the size of the array smaller, but to remove the leading and trailing spaces in each element.

This works:
String[] a = { " 1 ", " 2 " };
for (int i = 0; i < a.length; i++) {
    a[i] = a[i].trim();
}


This does not work:
for (String s: a) {
    s = s.trim();
}
Share |
| Comment  | Tags
 
Easy email testing with http://www.ximailstop.com