Directly from this Scanner API:
String input = "1 fish 2 fish red fish blue fish";
Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");
System.out.println(s.nextInt());
System.out.println(s.nextInt());
System.out.println(s.next());
System.out.println(s.next());
s.close();
First we make our habits; then our habits make us.
I'd say close the stream, because ingraining a habit like closing resources in finally
blocks make sense.
I don't think so, but it's best to close it anyway in case you change your code to use a stream. It's also a good habit, one that you really want to get into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With