Java String using it's function - Programming Examples
String is the most widely used square in Java programming. This is the reason that string programs are used in Java interviews to reach coding skills.
example:
is same as:
Java string provides several methods for class string operation, such as comparison (), concat (), equal (), partition (), length (), replace (), compare (), intern (), substring () e.t.c.
जावा स्ट्रिंग क्लास स्ट्रिंग पर ऑपरेशन करने के लिए कई तरीके प्रदान करता है जैसे तुलना (), concat (), बराबर (), विभाजन (), लंबाई (), प्रतिस्थापित करें (), तुलना करें (), intern (), substring () आदि।
Java String Example
String Change Casepublic class StringChangeCase {
public static void main(String[] args) {
String str = "Hello World";
String strLower = str.toLowerCase();
String strUpper = str.toUpperCase();
System.out.println("Original String: " + str);
System.out.println("String changed to lower case: " + strLower);
System.out.println("String changed to upper case: " + strUpper);
}
}
output
Original String: Hello World
String changed to lower case: hello world
String changed to upper case: HELLO WORLD
Java String class methods
The java.lang.String class provides many useful methods to perform operations on sequence of char values.
No. | Method | Description |
---|---|---|
1 | char charAt(int index) | returns char value for the particular index |
2 | int length() | returns string length |
3 | static String format(String format, Object... args) | returns a formatted string. |
4 | static String format(Locale l, String format, Object... args) | returns formatted string with given locale. |
5 | String substring(int beginIndex) | returns substring for given begin index. |
6 | String substring(int beginIndex, int endIndex) | returns substring for given begin index and end index. |
No comments:
Post a Comment