< Java Tutorial

Java string

← Previous Next →


String is probably the most commonly used class in java library.
String class is encapsulated under java.lang package.

In java, every string that you create is actually an object of Class String.
One important thing to notice about string object is that string objects are immutable that means once a string object is created it cannot be altered.

How to create String ?

String message1= "Hello world!";
String message2= new String("Hello world!");

Example:

public class StringExample {
   public static void main(String args[]) {
      String string1 = "World!";
      System.out.println(string1);
   }
}

 

 

← Previous Next →