I have a phrase on a string and I want to split it on other 5 or more string without spaces.
For example:
String test = "hi/ please hepl meok?";
and I want :
String temp1 = "hi/";
String temp2 = "please";
String temp3 = "help";
String temp4 = "meok?";
I dont want to add that in an array, because I want to split the temp4 to 3 more strings.
eg
->> temp4 after splitting:
temp4 = "me"
temp5 = "ok"
temp6 = "?"
This Question is asked because I want to write a method to decode a String phrase from a LinkedHashMap set with some decodes. Thanks. If my way is wrong please guide me! 🙂
Given your string, split() will do the trick
tokens[0] will then be
"hi/", tokens[1] will be"please"and so on.EDIT you’re going to be storing your strings in an array first in any case when split is used, use StringTokenizer if you want to loop through them individually.