What is String in Java?
A String is an object of the String class, which is part of the java.lang package. A String can be created by using the String literal:
syntax:
String name = "John";
By using the new keyword and the constructor of the String class:
Syntax:
String name = new String("John");
Java String class provides a lot of methods to perform operations on strings such as compare(), concat(), equals(), split(), length(), replace(), compareTo(), intern(), substring() etc.
Java String Programs
A String in Java is a sequence of characters that can be used to store and manipulate text data and It is basically an array of characters that are stored in a sequence of memory locations. All the strings in Java are immutable in nature i.e. once the string is created we can’t change it. This article provides a variety of programs on strings, that are frequently asked in the technical round in various software engineering interviews including various operations such as reversing, Iteration, palindrome, swapping, and splitting of strings etc.
Here, you practice all basic to advanced programs related to strings and each program comes with a detailed description, Java code, and output. All of the examples have been thoroughly tested on both Windows and Linux systems.
- Basic Strings Questions
- Advance Strings Questions