Created: 2023-08-26 16:05
Status: #concept
Subject: Programming
Tags: Java Java Data Type java.util.Scanner java.lang.StringBuilder

Java String Class

It is an object type, which is also built-into Java with the java.lang Java Package.

  • we can use it like a primitive data type to declare variables.
  • we use the java.util.Scanner utility object to scan strings from System.in (stdin) or Java Files.

Scanner scan = new Scanner(System.in);

// getting user input
String userInput = scan.nextLine();

// string concatenation & string interpolation
System.out.println("You inputted: " + userInput); 
System.out.println(String.format("You inputted: %s", userInput));

// typecasting to string
Integer someInteger = 777;
System.out.println(String.valueOf(someInteger));
System.out.println(someInteger.toString());
System.out.println("" + someInteger);

static Methods

Instance Methods

References