Using Strings in Java

In Java, a string is an object that represents a sequence of characters. Unlike primitive data types like int or float, String is a class with some unique properties that make it different from other classes. Strings in Java are immutable, meaning once a String object is created, its value cannot be changed. If you try to change a string, a new String object will be created, and the original one will remain unchanged. Because strings are immutable, any method that modifies a string will return a new one while keeping the original one untouched. Strings can also be concatenated using the + operator, and the String class overrides the Equals() method to provide content-based equality testing. In this Java String Example, we create two strings, concatenate them, and print them using System.out.println() method. Click Execute to run the Java String Example online and see the result.
Using Strings in Java Execute
public class StringExample {
    public static void main(String[] args) {
        String str1 = "Hello";
        String str2 = "World";

        System.out.println(str1 + ", " + str2 + "!");
Updated: Viewed: 48 times