String str = "The quick brown fox jumps over the lazy dog"; StringTokenizer st = new StringTokenizer(str); while (st.hasMoreElements()) { System.out.println(st.nextElement()); }
String str = "1001,John,Doe,5000"; StringTokenizer st = new StringTokenizer(str, ","); while (st.hasMoreElements()) { System.out.println(st.nextElement()); }This code will break the given string "1001,John,Doe,5000" into tokens with the delimiter "," and print them line by line. The java.util package library contains classes for collections, date and time, event model, internationalization, and more.