- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
The Scanner class in Java, part of the java.util package, is a versatile tool for obtaining input of various primitive types and strings. It is widely used for reading user input from different sources such as the console, files, and strings. The Scanner class breaks the input into tokens using a delimiter, which is whitespace by default.
Basic Usage
To use the Scanner class, you need to create an instance of it and pass the input source to its constructor. For example, to read input from the console, you can use System.in as the input source:
import java.util.Scanner;public class ScannerDemo {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("Enter your name:");String name = sc.nextLine();System.out.println("Name: " + name);sc.close();}}Copied!✕CopyReading Different Data Types
The Scanner class provides various methods to read different types of data. Here are some commonly used methods:
Java User Input (Scanner class) - W3Schools
The Scanner class is used to get user input, and it is found in the java.util package. To use the Scanner class, create an object of the class and use any of the available methods found in the Scanner class …
See results only from w3schools.comJava For Loop
Java For Loop When you know exactly how many times you want to loop through a …
Java Modifiers
The public keyword is an access modifier, meaning that it is used to set the access …
Java Iterator
Java Iterator An Iterator is an object that can be used to loop through collections, …
Java Data Structures
Java Data Structures Data structures are ways to store and organize data so you …
List Sorting
Java Sort a List In the previous chapters, you learned how to use two popular lists …
W3Schools Exercise
I completed a JAVA exercise on w3schools.com You completed the JAVA …
Java Output
Print Text You learned from the previous chapter that you can use the println() …
Java String Methods
Well organized and easy to understand Web building tutorials with lots of examples of …
Java Booleans
Java Booleans Very often in programming, you will need a data type that can only …
Run Example
The W3Schools online code editor allows you to edit code and view the result in …
Scanner Class in Java - GeeksforGeeks
Jul 23, 2025 · We can use this class to read input from a user or a file. In this article, we cover how to take different input values from the user using the Scanner …
Scanner (Java Platform SE 8 ) - Oracle Help Center
An instance of this class is capable of scanning numbers in the standard formats as well as in the formats of the scanner's locale. A scanner's initial locale is the value returned by the …
Java Scanner (With Examples) - Programiz
The Scanner class of the java.util package is used to read input data from different sources like input streams, users, files, etc. In this tutorial, we will learn about the Java Scanner and its methods with the …
Scanner Class in Java - Online Tutorials Library
The Java Scanner class is a simple text scanner that can parse primitive types (int, double, long, etc.) and strings using regular expressions. The Scanner class plays an important role in Java by providing …
Java Scanner class with examples - BeginnersBook
Sep 11, 2022 · In this tutorial, you will learn Java Scanner class and how to use it in java programs to get the user input. This is one of the important classes as it provides you various methods to capture …
Scanner Class in Java: Syntax, Methods, and Examples
Dec 15, 2025 · Learn about the Java Scanner class with hands-on examples. Explore its syntax, core methods, and how to implement it for robust user input.
Mastering the Java Scanner Syntax: A Comprehensive Guide
Mar 21, 2026 · Understanding the syntax and usage of the `Scanner` class is essential for any Java developer looking to build user-friendly and interactive programs. This blog post will explore the …
Java Scanner Class Tutorial With Examples - Software …
Apr 1, 2025 · Now that you have seen the various constructors and methods provided by Scanner class, let’s now implement some of the examples to …
Scanner Class in Java (With Examples) - Scaler Topics
Apr 3, 2024 · The scanner class is the simplest way to take input in Java and provides various methods (discussed above) to do so. You can use it when you …