Explain the difference in data entry in the Scanner, Console и BufferedReader bReader = new BufferedReader (new InputStreamReader(System.in)); and which one is better to use?

    1 answer 1

    The difference is simple

    Scanner is designed to parse any text and input from the terminal, as a special case. He knows how to filter out all sorts of numbers, etc. Convenient for simple parsing of texts and for all educational tasks such as "enter a number from zero to three."

    The console is needed for inputs from the console, but sometimes it does not work: sometimes there is no console and then there’s no way to use this thing. The console does not know how to parse anything, but only to provide input, including secure password entry.

    BufferedReader is needed to buffer reading from any stream. As a special case, you can buffer input from the terminal. Sometimes used for the readLine method, when it is difficult or just a day to process text in blocks. For the purpose of reading text from standard inputs or manual user input is quite suitable option. But with this approach, you will have to parse the numbers manually, which is not too complicated.

    No one can tell you what to use. It depends on the task and conditions of implementation. If the data comes in via standard input, you should probably expect the Console to let you down. Scanner is useful, but it may turn out to be too useful and slow down everything if there is a lot of data. Buffered input can also slip you byaku, so in any case, you should consider the source of the data, the amount of data and their nature to make some kind of decision.

    • Thanks for pushing "cy6erGn0m" - turtles