I am new to java and i am trying to create a simple program which would parse a string using delimiter. However whenever i try do this instead of printing the lines like this:
Hello World
I am Bob
how are you
it prints out each character individually on its own line. Here is my code:
import java.util.Scanner;
public class ScannerDemo {
public static void main(String args[]){
String s = "Hello World|I am bob|how are you ";
Scanner scan = new Scanner(s);
scan.useDelimiter("|");
System.out.println(scan.next());
while (scan.hasNext()){
System.out.println(scan.next());
}
}
}
Any help would be apreciated