How do I use a delimiter with Scanner.useDelimiter in Java?

The scanner can also use delimiters other than whitespace. Easy example from Scanner API: String input = “1 fish 2 fish red fish blue fish”; // \\s* means 0 or more repetitions of any whitespace character // fish is the pattern to find Scanner s = new Scanner(input).useDelimiter(“\\s*fish\\s*”); System.out.println(s.nextInt()); // prints: 1 System.out.println(s.nextInt()); // prints: 2 … Read more

What does Scanner input = new Scanner(System.in) actually mean?

Alright, let’s elaborate with some simplified explanation about the Scanner class. It is a standard Oracle class which you can use by calling the import java.util.Scanner. So let’s make a basic example of the class: class Scanner { InputStream source; Scanner(InputStream src) { this.source = src; } int nextInt() { int nextInteger; //Scans the next token of the … Read more