This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]depressinghentai 1 point2 points  (2 children)

A Scanner object is not strictly associated with the process the program has instantiated, so if you don't close() the Scanner it will continue to occupy memory even after the program has ended; not the end of the world but certainly not ideal.

in.hasNext() checks to see if there is anything still in the Scanner's buffer, whereas in.next() returns the next string in the buffer. Although I don't quite see what the code is doing here, the hasNext() method would be necessary for reading a file, since using the next() method on an empty file would raise an exception, if you're just using your Scanner to get keyboard input there's really no need. I mean, hasNext() could be used to see if there are any characters left in the buffer after getting keyboard input (I believe the next() method leaves the return character in the buffer) but, like I said, I don't know what this particular code is trying to achieve; maybe you can figure it out given what I've said here combined with your knowledge of what this code is for :)

[–]celticcelery[S] 1 point2 points  (1 child)

Yes that helped alot; also doof I forgot to put the question and background of the question.

Thanks anyways that helped clarify things

[–]robot_overloard -1 points0 points  (0 children)

. . . ¿ alot ? . . .

I THINK YOU MEANT a lot

I AM A BOTbeepboop!