GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||
GeezerVison is showing www.geeksforgeeks.org — String Class in Java - GeeksforGeeks String Class in JavaLast Updated : 29 Sep, 2026 The String class in Java is used to represent and work with sequences of characters. It is part of the java.lang package and provides various methods for creating, comparing, searching, and manipulating strings. String objects are immutable, meaning their values cannot be changed after creation.
Key Features of the String Class1. ImmutableImmutable means that once a String object is created, its value cannot be changed. Example:
Explanation: The line text.charAt(0) = 'H'; causes a compile-time error because charAt(0) returns a read-only char, not a variable. String is immutable in Java, you cannot modify its characters directly. 2. Thread-SafeString objects in Java are considered thread-safe because they are immutable. Once a String object is created, its value cannot be modified, so multiple threads can safely read and share the same String object without changing its contents.
3. Supports Various Utility MethodsString is a predefined final class in Java present in java.lang package. It provides various methods to create, manipulate, and compare strings, like length(), charAt(), concat(), equals(), etc.
Output Length of String-> 11 Changed String ->HELLO GEEKS 4. Implements InterfacesThe String class implements several interfaces that provide features such as character-sequence handling, comparison, serialization, and constant description.
String Constructors in JavaIn Java, String constructors are used to create new String objects from different sources like character arrays, byte arrays, or another string. Although strings in Java are usually created using string literals, the String class also provides constructors for more control. Let us check these constructors using a example demonstrating the use of them.
Output String using new keyword: Hello Java String from char array: JAVA String from byte array: Hello String Constructors Table
Comment Explore | ||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |