Please explain me the difference between scanner and the buffer reader?

0 votes
Hi, I have a doubt why buffer reader is safer to take user input in java?

Can you explain that to me?

Thank you,
Aug 2 in Java by Bipasa
97 views

2 answers to this question.

0 votes
  1. BufferedReader is synchronous while Scanner is not. 
  2. BufferedReader should be used if we are working with multiple threads.
  3. BufferedReader has significantly larger buffer memory than Scanner.
  4. The Scanner has a little buffer as opposed to the BufferedReader, but it’s more than enough.
  5. BufferedReader is a bit faster as compared to scanner because the scanner does parsing of input data and BufferedReader simply reads a sequence of characters.
I hope this will help you to understand the difference,
Thank you
answered Aug 2 by sampriti
• 1,100 points
0 votes

As per your question for reading a text file you should use BufferedReader because Scanner hides IOException while BufferedReader throws it immediately.

BufferedReader is synchronized and Scanner is not.

Scanner is used for parsing tokens from the contents of the stream.

BufferedReader just reads the stream.

answered Aug 27 by Sirajul
• 37,930 points

Related Questions In Java

+1 vote
1 answer

Can you please explain the difference between string, string buffer and string builder?

String are immutable where as StringBuffer and ...READ MORE

answered Jul 4 in Java by Akash
• 160 points
92 views
0 votes
1 answer

Can you explain what is the difference between hashtable and hashmap?

Hi, Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for ...READ MORE

answered Aug 14 in Java by anonymous
56 views
0 votes
2 answers

What is the difference between implements and extends?

Extends : This is used to get attributes ...READ MORE

answered Aug 3, 2018 in Java by samarth295
• 2,190 points
626 views
0 votes
1 answer

What is the difference between jdk and jre?

JRE: It stands for Java Runtime Environment. ...READ MORE

answered Apr 20, 2018 in Java by Akrati
• 3,150 points
159 views
0 votes
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,540 points
78 views
0 votes
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
67 views
0 votes
1 answer

Performance difference of if/else vs switch statement in Java

The thing you are worried about is ...READ MORE

answered Jul 26, 2018 in Java by geek.erkami
• 2,640 points
530 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
592 views
0 votes
2 answers

What is the difference between Map and HashMap in java?

The basic difference is : Map is ...READ MORE

answered Aug 28 in Java by Sirajul
• 37,930 points
657 views
0 votes
2 answers

Can you give me the proper difference between java.util.Date vs java.sql.Date ?

The java.util.date class represents a particular moment in time, with ...READ MORE

answered Aug 27 in Java by Sirajul
• 37,930 points
128 views