JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label Scanner. Show all posts
Showing posts with label Scanner. Show all posts

BufferedReader vs Scanner in Java

4:27 AM
BufferedReader vs Scanner in Java Here is the 5 key differences between the Scanner and BufferedReader class of Java API: 1. Scanner is a much more powerful utility than BufferedReader. It can parse the user input and read int, short, byte, float, long and double apart from String. On the other hand  BufferedReader  can only  read String in Java . 2. BuffredReader has significantly large buffer (8KB) than Scanner (1KB), which means if you are reading long String from file, you should use BufferedReader but for short input and input other than String, you can use Scanner class. 3. BufferedReader is older than Scanner. It's present in Java from JDK 1.1 onward but Scanner is only introduced in JDK 1.5 release. 4. Scanner uses  regular expression  to read and parse text input. It can accept custom delimiter and parse text into primitive data type e.g. int, long, short, float or double using  nextInt() ,  nextLong() ,  nextShort() ,  nextFloat() ,  and  nextDouble()  methods, while 

.