How can I trim characters in Java? e.g.
String j = “joejill”.Trim(new char[] {“”});
j should be
"joejill"
String j = “jackjoejill”.Trim("jack");
etc
Apache Commons has a great StringUtils class (org.apache.commons.lang.StringUtils). In StringUtils there is a strip(String, String) method that will do what you want.
StringUtils
strip(String, String)
I highly recommend using Apache Commons anyway, especially the Collections and Lang libraries.
2.1m questions
2.1m answers
60 comments
57.0k users