i have the following code which will tokenize the string to create list of Objects:
import java.util.StringTokenizer;
public class TestStringTokenizer {
private final static String INTERNAL_DELIMETER = "#,#";
private final static String EXTERNAL_DELIMETER = "#|#";
public static void main(String[]aregs){
String test= "1#,#Jon#,#176#|#2#,#Jack#,#200#|#3#,#Jimmy#,#160";
StringTokenizer tokenizer = new StringTokenizer(test, EXTERNAL_DELIMETER);
while(tokenizer.hasMoreElements()){
System.out.println(tokenizer.nextElement());
//later will take this token and extract elements
}
}
}
What i expected output was
1#,#Jon#,#176
2#,#Jack#,#200
3#,#Jimmy#,#160
What i got was :
1
,
Jon
,
176
2
,
Jack
,
200
3
,
Jimmy
,
160
if i change the internal delimeter to some thing like , it will work properly why is this behavior happening ?
StringTokenizerdoesn't take#|#as one single delimiter, but as 3 delimiters. Kindly go through the API of that class to understand how it works.