The Java String intern() return the reference of a equal string literal present in string pool. String literals are automaically interned in Java.
The Java String contains() searches a substring in the given string. It returns true if substring are found in this string otherwise returns false. 1. String contains() method Use String.contains() to find is a substring is present in given string or not. Please remember that this method is case sensitive. 1.1. Method syntax The method […]
Java String toLowerCase() returns a string which is result of converting all characters in given string to lowercase. Convert string to lowercase in Java.
The Java String toUpperCase() returns a string which is result of converting all characters in given string to UPPERCASE. Read more: Java example capitalize the string 1. String toUpperCase() method Use String.toUpperCase() converts any string to UPPECASE letters. 1.1. Method syntax String toUpperCase() method is overloaded and comes in two variants. 1.2. ‘null’ is not […]
The Java String split() returns string array after it splits the string around matches of the method argument regular expression. 1. String split() method Use String.split() to split a string to string array by tokenizing with delimiter substring or regular expression. 1.1. Method syntax String split() method is overloaded and comes in two variants. 1.2. […]
The Java String replaceAll() returns a string after it replaces each substring of that matches the given regular expression with the given replacement. 1. String replaceAll() method Use String.replaceAll(String regex, String replacement) to replace all occurrences of a substring (matching argument regex) with replacement string. 1.1. Method syntax 1.2. throws PatternSyntaxException Watch out that replaceAll() […]
The Java String replaceFirst() method replaces the first substring ‘regex’ found that matches the given argument substring (or regular expression) with the given replacement substring. The substring matching process start from beginning of the string (index 0). 1. String replaceFirst(String regex, String replacement) method The String replaceFirst() method uses regular expression to find and replace […]
The Java String replace() method replaces each substring of this string that matches the literal target substring. The matching process starts at index 0.
The Java String concat() method concatenates the method argument string to the end of string object. 1. String concat(String str) method Internally, Java creates a new character array with combined length of string object and argument string, and copies all content from both strings into this new array. Finally, combiner character array is converted to […]
Java String substring() example. Learn to get substring of a string from given start index to end index. A valid index is between 0 and length of string.
Java String lastIndexOf() method. It returns the last index of specified character or string as method argument. If argument is not found it returns -1.
The Java String indexOf() method returns the index of given character or string as method argument. If argument is not found in string, method returns -1. The index counter for a string starts from zero.
Java String hashCode() method returns the hash code for the String. Hash code value is used in hashing based collections like HashMap, HashTable etc. This method must be overridden in every class which overrides equals() method. Read More: Contract between hashCode() and equals() methods 1. String hashCode() method The hash code for a String object […]
Java String endsWith() method is used to check the suffix of the string. It verifies if given string ends with argument string or not. 1. Java String endsWith(String str) method Java program to check if a string ends with suffix argument string ‘str’. Program output. String endsWith() method does not accept regular expression as argument. […]
Java String startsWith() method check if a string starts with prefix argument string. does not accept regex as argument. null argument is also not allowed.
Java String compareToIgnoreCase() example compares two strings lexicographically ignoring case. Difference in compareToIgnoreCase() vs equalsIgnoreCase().
Java String compareTo() method example. Learn to compare two strings lexicographically. We can consider this string comparison dictionary based comparison.
Java String equalsIgnoreCase() method example to compare strings in case-insensitive manner. Learn the difference between equalsIgnoreCase() and equals().
Java String equals() method is used to compare a string with the method argument object. 1. Java String.equals() method String class overrides equals() method from Object class. The equality is done in case-sensitive manner. Use equals() method to check the equality of string contents. Do not use ‘==’ operator. It checks the object references, which […]
Java String charAt() method example. It returns the character at the specified index argument in the string object or literal. Argument must be valid index.