{"id":79152,"date":"2020-06-22T09:00:56","date_gmt":"2020-06-22T03:30:56","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=79152"},"modified":"2020-06-22T09:00:56","modified_gmt":"2020-06-22T03:30:56","slug":"java-scanner-class","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/","title":{"rendered":"Java Scanner Class &#8211; Methods and Constructors"},"content":{"rendered":"<p>In our previous article, we discussed the implements keyword in Java. In this article, we will discuss a special class in Java which is the <strong>Java Scanner Class<\/strong>.<\/p>\n<p>Till now, we learned how to print something on the user\u2019s screen with a Java program. But, if you wish to take input from the user while writing a program, then you can use the Scanner class of Java.<\/p>\n<p>In this article, we will learn about this class along with its methods and will understand them with example code snippets and programs.<\/p>\n<h3>Scanner Class in Java<\/h3>\n<p>The Scanner class in Java is a predefined class that helps us to take input from the user. This class is present in the java.util package and we need to import this package inside our Java program to use this class.<\/p>\n<p>There are many predefined methods in the java.util.Scanner class for performing various operations like reading and parsing various primitive types. Basically, we have to create the object of the Scanner class to use these methods.<\/p>\n<p>The Scanner class can also parse strings and primitive types by using regular expressions.<\/p>\n<p>The Scanner class in Java extends the Object class and implements the Cloneable and Iterator interfaces.<\/p>\n<h3>Importing Java Scanner Class<\/h3>\n<p>To use the methods and functionalities of the Scanner class, we need to include the class in our Java program by importing the java.util package using the import keyword at the beginning of the code.<\/p>\n<p>We can do it in two ways:<\/p>\n<p><strong>1. import java.util.Scanner;<\/strong><br \/>\n<strong>\/\/imports the Scanner class<\/strong><\/p>\n<p><strong>2. import java.util.*;<\/strong><br \/>\n<strong>\/\/imports all the classes of java.util package<\/strong><\/p>\n<h3>Using Scanner Class in Java<\/h3>\n<p>After importing the Scanner class, we have to get the instance of the Scanner class to read the input from the user. We will create an instance and we will pass the Input Stream System.in while creating the instance as follows:<\/p>\n<p><strong>Scanner scannerObject = new Scanner(System.in);<\/strong><\/p>\n<p>Here, by writing the Scanner scannerObject, we are declaring the scannerObject as the object of the scanner class. System.in denotes that the input will be given to the System.<\/p>\n<h3>Constructors of Java Scanner Class<\/h3>\n<p>The Scanner class contains the constructors for specific purposes that we can use in our Java program.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>S.N.<\/b><\/td>\n<td><b>Constructor<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(File source)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a Scanner object that produces values scanned from the specified file.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(File source, String charsetName)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor constructs a new Scanner object that produces values scanned from the specified file.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(InputStream source)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a new Scanner object that produces values scanned from the specified input stream.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(InputStream source, String charsetName)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a new Scanner that produces values scanned from the specified input stream.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(Readable source)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a new Scanner that produces values scanned from the specified source.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(String source)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a new Scanner that produces values scanned from the specified string.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(ReadableByteChannel source)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a new Scanner that produces valgues scanned from the specified channel.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(ReadableByteChannel source, String charsetName)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a new Scanner that produces values scanned from the specified channel.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">9)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(Path source)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a new Scanner that produces values scanned from the specified file.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">10)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Scanner(Path source, String charsetName)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a new Scanner that produces values scanned from the specified file.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Methods of Java Scanner Class<\/h3>\n<p>Now, we will discuss some important methods of the Scanner class without which taking the input is impossible.<\/p>\n<p>Following is the list of methods that we use for various data types.<\/p>\n<table style=\"height: 608px\" width=\"697\">\n<tbody>\n<tr>\n<td><b>Method<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean nextBoolean()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method reads the boolean value from the user.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">byte nextByte()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It reads the byte value from the user.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">double nextDouble()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It accepts the input in double datatype from the user.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">float nextFloat()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It takes the float value from the user.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">int nextInt()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It scans the input in the int type from the user.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">String nextLine()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method reads the String value from the user.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">long nextLong()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method reads the long type of value from the user.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">short nextShort()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It reads the short type of value from the user.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">char next()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It reads the character input from the user.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Code to understand the above methods<\/h4>\n<p>Let\u2019s see a single java program that uses all the above-mentioned methods of the Scanner class:<\/p>\n<p><strong>Code to read data of various types using Scanner class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.scannerclass;\nimport java.util.Scanner;\npublic class ScannerMethodDemo {\n  public static void main(String[] args) {\n    Scanner sc = new Scanner(System. in );\n    System.out.println(\"Taking inputs from user\");\n    System.out.println(\"Enter name of the Employee:\");\n    \/\/ String input \n    String name = sc.nextLine();\n    System.out.println(\"Enter post:\");\n    String post = sc.nextLine();\n    System.out.println(\"Enter gender:\");\n    \/\/ Character input \n    char gender = sc.next().charAt(0);\n\n    \/\/ Numerical data input \n    System.out.println(\"Enter age:\");\n    int age = sc.nextInt();\n    System.out.println(\"Enter mobile number:\");\n    long mobileNo = sc.nextLong();\n    System.out.println(\"Enter salary\");\n    double salary = sc.nextDouble();\n\n    \/\/ Print the values to check if the input was correctly obtained. \n    System.out.println(\"\\nName: \" + name);\n    System.out.println(\"Post: \" + post);\n    System.out.println(\"Gender: \" + gender);\n    System.out.println(\"Age: \" + age);\n    System.out.println(\"Mobile Number: \" + mobileNo);\n    System.out.println(\"Salary: \" + salary);\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Taking inputs from the user<br \/>\nEnter the name of the Employee:<br \/>\nAvina Garg<br \/>\nEnter post:<br \/>\nResearch Analyst<br \/>\nEnter gender:<br \/>\nF<br \/>\nEnter age:<br \/>\n23<br \/>\nEnter mobile number:<br \/>\n95687968756<br \/>\nEnter salary<br \/>\n30000.00<br \/>\nName: Avina Garg<br \/>\nPost: Research Analyst<br \/>\nGender: F<br \/>\nAge: 23<br \/>\nMobile Number: 95687968756<br \/>\nSalary: 30000.00<\/div>\n<h3>Java hasNextDataType() Methods<\/h3>\n<p>There are times when we need to check if the next value we read is of a certain type or if the input has EOF or not. Then, we check if the scanner\u2019s input is of the type we want with the help of hasNextXYZ() functions where XYZ is the datatype we want to use.<\/p>\n<p>The method returns true if the scanner has a token of that type, otherwise returns false. There are some boolean methods for each data type.to check whether the next token of a particular data type is available in the given input or not. The following table shows them:<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Method\u00a0<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean hasNextBoolean()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks if the next token in this scanner&#8217;s input\u00a0 interprets as a Boolean using the nextBoolean() method or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean hasNextByte()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks if the next token in this scanner&#8217;s input interprets as a Byte using the nextByte() method or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean hasNextDouble()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks whether the next token in this scanner is a BigDecimal input using the nextBigDecimal() method or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean hasNextFloat()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks whether the next token in this scanner&#8217;s input interprets as a Float using the nextFloat() method or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean hasNextInt()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks whether the next token in this scanner&#8217;s input interprets as an int using the nextInt() method or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean hasNextLine()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks whether there is another line in the input of this scanner or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean hasNextLong()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks whether the next token in this scanner&#8217;s input interprets as a Long using the nextLong() method or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">boolean hasNextShort()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks whether the next token in this scanner&#8217;s input interprets as a Short using the nextShort() method or not.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Code to read some values using Scanner class and print their mean:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.scannerclass;\nimport java.util.Scanner;\npublic class ScannerMethodsDemo1 {\n  public static void main(String[] args) {\n    System.out.println(\"Enter the numbers and any character other than an integer to get their mean:\");\n    Scanner sc = new Scanner(System. in );\n\n    \/\/ Initialize sum and count of input elements \n    int sum = 0,\n    count = 0;\n\n    \/\/Checking if an int value is available \n    while (sc.hasNextInt()) {\n      \/\/ Read an int value \n      int num = sc.nextInt();\n      sum += num;\n      count++;\n    }\n    int mean = sum \/ count;\n    System.out.println(\"Mean of the numbers is: \" + mean);\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Enter numbers and any character other than an integer to get the Mean of numbers:<br \/>\n2<br \/>\n4<br \/>\n6<br \/>\n4<br \/>\n10<br \/>\n24<br \/>\n57<br \/>\n80<br \/>\nA<br \/>\nMean of the numbers is: 26<\/div>\n<h3>Working of Java Scanner class<\/h3>\n<p>The Scanner class reads an entire line and divides the line into tokens. Tokens are small elements that have some meaning to the Java compiler.<\/p>\n<p>Suppose there is an input string:<\/p>\n<p>His age is 23<\/p>\n<p>In this case, the scanner object will read the entire line and divide the string into tokens: &#8220;His&#8221;, &#8220;age&#8221; &#8220;is&#8221; and &#8220;23&#8221;. The object then iterates over each token and reads each token using its different methods.<\/p>\n<p><em><strong>Note:<\/strong><\/em> By default, the use of whitespace is to divide tokens.<\/p>\n<h3>String Tokenization using the Scanner class<\/h3>\n<p>Java Scanner class is also used to parse the string into tokens and perform operations on them. There are some useful methods provided by the Scanner class to do this. These methods are:<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Method<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Stream&lt;String&gt; tokens()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method gives a stream of delimiter-separated tokens from the Scanner object which is in use.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">String toString()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns the string representation of Scanner using.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Scanner useDelimiter()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method sets the delimiting pattern of the Scanner which is in use to the specified pattern.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">void close()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method closes this scanner.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Code to understand the String Tokenization with the Scanner class:<\/strong><\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.scannerclass;\nimport java.util.Scanner;\npublic class ScannerTokens1 {\n  public static void main(String args[]) {\n    String s = \"Techvidvan%Java%Tutorials%Scanner%program%3\";\n    \/\/Initialize Scanner object \n    Scanner sc = new Scanner(s);\n    \/\/Initialize the string delimiter  \n    sc.useDelimiter(\"%\");\n    \/\/Prints stream of delimiter-separated tokens  \n    sc.tokens();\n    \/\/Printing the tokenized Strings  \n    while (sc.hasNext()) {\n      System.out.println(sc.next());\n    }\n    sc.close();\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Techvidvan<br \/>\nJava<br \/>\nTutorials<br \/>\nScanner<br \/>\nprogram<br \/>\n3<\/div>\n<p><strong>Example 2:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.scannerclass;\nimport java.util.Scanner;\npublic class ScannerTokens2 {\n  public static void main(String args[]) {\n    String input = \"5 Java 2 Java techvidvan Java tutorial Java\";@SuppressWarnings(\"resource\")\n    Scanner sc = new Scanner(input).useDelimiter(\"\\\\s*Java\\\\s*\");\n    \/\/ \\\\s* means 0 or more repetitions of any whitespace character   \n    \/\/Java is the pattern to find \n    sc.tokens();\n    System.out.println(sc.nextInt()); \/\/ prints: 5  \n    System.out.println(sc.nextInt()); \/\/ prints: 2  \n    System.out.println(sc.next()); \/\/ prints: techvidvan  \n    System.out.println(sc.next()); \/\/ prints: tutorial         \n    \/\/close the scanner  \n    sc.close();\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">5<br \/>\n2<br \/>\ntechvidvan<br \/>\ntutorial<\/div>\n<p><strong>Example 3:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import java.util. * ;\npublic class ScannerTokens3 {\n  public static void main(String args[]) {\n    String myStr = \"Hello\/This is TechVidvan\/Java Tutorials\/Scanner class\";\n    \/\/Create a scanner class object with the specified String  \n    Scanner scanner = new Scanner(myStr);\n    \/\/Changing the delimiter of this scanner  \n    scanner.useDelimiter(\"\/\");\n    \/\/Printing the tokenized Strings  \n    System.out.println(\"---The Tokenized Strings are---\");\n    while (scanner.hasNext()) {\n      System.out.println(scanner.next());\n    }\n    \/\/Displaying the new delimiter  \n    System.out.println(\"Delimiter used: \" + scanner.delimiter());\n    scanner.close();\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8212;The Tokenized Strings are&#8212;<br \/>\nHello<br \/>\nThis is TechVidvan<br \/>\nJava Tutorials<br \/>\nScanner class<br \/>\nDelimiter used: \/<\/div>\n<h3>Conclusion<\/h3>\n<p>This was all about Java Scanner class. The Scanner class plays a very important role in taking inputs from the user. It is present in the java.util package and comes with various constructors and methods to take inputs of all types of primitive data types and String types.<\/p>\n<p>It is also helpful in tokenizing the strings. We have discussed the concepts with examples for your better understanding. We hope this article will be helpful in studying the Scanner class in Java.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our previous article, we discussed the implements keyword in Java. In this article, we will discuss a special class in Java which is the Java Scanner Class. Till now, we learned how to&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79172,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2911,2912,2913,2914],"class_list":["post-79152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java-scanner-class","tag-java-scanner-example","tag-scanner-class-in-java","tag-scanner-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Scanner Class - Methods and Constructors - TechVidvan<\/title>\n<meta name=\"description\" content=\"What is Java Scanner class, its working &amp; usage, Importing Scanner class, Constructors and methods of Scanner class in java, hasNextDataType() Methods\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Scanner Class - Methods and Constructors - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"What is Java Scanner class, its working &amp; usage, Importing Scanner class, Constructors and methods of Scanner class in java, hasNextDataType() Methods\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-22T03:30:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Scanner-Class-in-java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Scanner Class - Methods and Constructors - TechVidvan","description":"What is Java Scanner class, its working & usage, Importing Scanner class, Constructors and methods of Scanner class in java, hasNextDataType() Methods","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/","og_locale":"en_US","og_type":"article","og_title":"Java Scanner Class - Methods and Constructors - TechVidvan","og_description":"What is Java Scanner class, its working & usage, Importing Scanner class, Constructors and methods of Scanner class in java, hasNextDataType() Methods","og_url":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-06-22T03:30:56+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Scanner-Class-in-java.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Java Scanner Class &#8211; Methods and Constructors","datePublished":"2020-06-22T03:30:56+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/"},"wordCount":1414,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Scanner-Class-in-java.jpg","keywords":["java scanner class","java scanner example","scanner class in java","scanner java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/","url":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/","name":"Java Scanner Class - Methods and Constructors - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Scanner-Class-in-java.jpg","datePublished":"2020-06-22T03:30:56+00:00","description":"What is Java Scanner class, its working & usage, Importing Scanner class, Constructors and methods of Scanner class in java, hasNextDataType() Methods","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Scanner-Class-in-java.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Scanner-Class-in-java.jpg","width":802,"height":420,"caption":"Scanner Class in java"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-scanner-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Java Scanner Class &#8211; Methods and Constructors"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=79152"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79152\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/79172"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=79152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=79152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=79152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}