Java String Class Methods:
The java.lang.String class in Java provides a wide range of methods to work with Strings. Here are some of the most commonly used methods:
String str = "Hello";
int length = str.length(); // returns 5
String str = "Hello";
char c = str.charAt(1); // returns 'e'
String str = "Hello, World!";
String subStr = str.substring(7); // returns "World!"
String str1 = "Hello";
String str2 = "World";
String concatStr = str1.concat(str2); // returns "HelloWorld"
String str = "Hello, World!";
int index = str.indexOf("World"); // returns 7
String str = "Hello, World!";
booleanstartsWith = str.startsWith("Hello"); // returns true
booleanendsWith = str.endsWith("World!"); // returns true
String str = "Hello, World!";
String lowerStr = str.toLowerCase(); // returns "hello, world!"
String upperStr = str.toUpperCase(); // returns "HELLO, WORLD!"
String str = " Hello, World! ";
String trimStr = str.trim(); // returns "Hello, World!"
String str = "Hello, World!";
String replaceStr = str.replace("o", "e"); // returns "Helle, Werld!"
These are just a few examples of the many methods available in the String class. By using these methods, you can manipulate and process Strings in a variety of ways in your Java programs.
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.