Let's say I have a continuous String name as temp. The string is divided by new lines, How can I use StringTokenizer on it and get each line separately?
String temp = "I
am
a
college
kid";
Thank You
Let's say I have a continuous String name as temp. The string is divided by new lines, How can I use StringTokenizer on it and get each line separately?
String temp = "I
am
a
college
kid";
Thank You
StringTokenizer st = new StringTokenizer(temp,"\n");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
Will do the job. However try to use split method of string class like
String lines[] = string.split("\\r?\\n");
StringTokenizer st = new StringTokenizer(temp,System.lineSeparator());
while (st.hasMoreTokens()) {
println(st.nextToken());
}