Reputation: 843
I need to parse an input-line character by character, and this will be done through several methods. To do it char by char, I am using useDelimiter(""). My question is: do i need to set this delimiter in every method? Or is it enough once, at the beginning?
e.g.
void start() {
Scanner in = new Scanner(System.in);
in.useDelimiter("");
char first = in.next();
readSecond(in);
...
}
void readSecond(Scanner in) {
//in.useDelimiter(""); <-- is this needed?
char second = in.next();
...
}
Example input: A5c*vd
Thanks !
Upvotes: 0
Views: 216
Reputation: 53819
Once set, the delimiter stays the same.
Therefore, you do not need to set it again to the same value.
Upvotes: 1
Reputation: 68
You wouldn't have to set it every time if you declare and initialize the Scanner object in the class body that the methods are in. If you initialize the Scanner in each method, then I think you would have to set the delimiter in each method body.
Upvotes: 2