I have a string like this:
mysz = \"name=john age=13 year=2001\";
I want to remove the whitespaces in the string. I tried trim()
You've already got the correct answer from Gursel Koca but I believe that there's a good chance that this is not what you really want to do. How about parsing the key-values instead?
import java.util.Enumeration;
import java.util.Hashtable;
class SplitIt {
public static void main(String args[]) {
String person = "name=john age=13 year=2001";
for (String p : person.split("\\s")) {
String[] keyValue = p.split("=");
System.out.println(keyValue[0] + " = " + keyValue[1]);
}
}
}
output:
name = john
age = 13
year = 2001