Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. 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!

    Reading Different Data Types

    The Scanner class provides various methods to read different types of data. Here are some commonly used methods:

    Feedback
  2. 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 …

  3. 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 …

  4. 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 …

  5. 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 …

  6. 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 …

  7. 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.

  8. 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 …

  9. 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 …

  10. 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 …