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 — Java String Methods - GeeksforGeeks Java String MethodsLast Updated : 28 Sep, 2026 Java String methods are built-in functions provided by the String class to perform various operations on strings. These methods help in manipulating, comparing, searching, and formatting text efficiently. They make string handling easier and more convenient in Java programs.
Output Length: 13 Uppercase: GEEKSFORGEEKS Substring: eksf Commonly Used Java String MethodsJava provides a rich set of String methods that help perform various operations like comparison, searching, modification of string. Let's Understand one by one. 1. int length() MethodThis method provides the total count of characters in the string.
Output 13 2. charAt(int i) MethodThis method returns the character at ith index.
Output W 3. String substring(int i) MethodThis method return the substring from the ith index character to end.
Output World! 4. String substring(int i, int j) MethodThis method returns the substring from i to j-1 index.
Output World 5. String concat( String str) MethodThis method appends the given string to the end of the current string.
Output Hello, World!!!! 6. int indexOf(String s) MethodThis method returns the index within the string of the first occurrence of the specified string. If the specified string s is not found in the input string, the method returns -1 by default.
Output 7 7. int indexOf(String s, int i) MethodThis method returns the index within the string of the first occurrence of the specified string, starting at the specified index.
Output 10 8. int lastIndexOf(String s) MethodThis method returns the index within the string of the last occurrence of the specified string. If the specified string s is not found in the input string, the method returns -1 by default.
Output 10 9. boolean equals(Object otherObj) MethodThis method compares this string to the specified object.
Output true 10. boolean equalsIgnoreCase(String anotherString) MethodThis method checks if two strings are equal, without considering letter case.
Output true 11. int compareTo(String anotherString) MethodThis method compares two string lexicographically.
Output 13 12. int compareToIgnoreCase(String anotherString) MethodThis method compares two string lexicographically, ignoring case considerations.
Output 13 13. String toLowerCase() MethodThis method converts all the characters in the String to lower case.
Output hello, world! 14. String toUpperCase() MethodThis method converts all the characters in the String to upper case.
Output HELLO, WORLD! 15. String trim() MethodThis method returns the copy of the String, by removing whitespaces at both ends. It does not modify the whitespace characters present between the text.
Output 'Hello, Trim!' 16. String replace(char oldChar, char newChar) MethodThis method returns a new string where all instances of oldChar are replaced by newChar.
Output Hexxo, Worxd! 17. boolean contains(CharSequence sequence) MethodThis method returns true if string contains the given string.
Output true 18. char[] toCharArray() MethodThis method converts the string into a new character array.
Output H e l l o 19. boolean startsWith(String prefix) MethodThis method returns true if string starts with this prefix.
Output true Common String Methods in Java
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. |