What is string ? what is substring ?
In : BSc IT Subject : Structure Programming Methodology - JavaA String in Java is a sequence of characters used to represent text. It is one of the most commonly used data types and is used to store words, sentences, or any kind of textual information.
In Java, strings are created using double quotes:
String name = "Hello Java";
trings are immutable , which means once created, their value cannot be changed.
A substring is a part (or portion) of a string. You can extract a substring from a string by specifying the starting and ending positions (indexes).
Java provides the substring() method for this:
Java provides the substring() method for this:
string.substring(startIndex, endIndex);
Example :
String str = "Hello Java";
String sub = str.substring(0, 5); // Extracts characters from index 0 to 4
System.out.println(sub); // Output: Hello
String sub = str.substring(0, 5); // Extracts characters from index 0 to 4
System.out.println(sub); // Output: Hello