Java String Inbuilt functions
There are different types of inbuilt functions available in the Java String class, all of them are listed below.
- Char chat At (int index)
It outputs the character indicated by the index. The selected index value must be between zero and length -1, inclusive. If index 0||>= length of String, it raises Index out of bounds exception
Syntax:
public char charAt(int index)
- Boolean equals (Object obj)
If the string matches the supplied string, it returns true; otherwise, it will return false.
Syntax:
public boolean equals (Object obj)
- Boolean equals ignore case(ignore case)
It functions similarly to the equals method; however, it does not take into account the case when comparing strings. It compares cases insensitively.
Syntax:
public Boolean ignore case(String):
- int compare To (String string)
Using the Unicode values of each character in the strings, this approach compares the two texts.
Syntax:
str1. equals(str2);
- int compare To ignore case(String string)
Similar to the CompareTo function, however, it avoids the case while comparing.
Syntax:
public int compareToIgnoreCase(String)
- boolean starts With (String prefix, int offset)
It determines whether or not the substring (beginning at the supplied offset index) has the prefix specified.
Syntax:
public boolean startWith(String prefix, int toffset);
- boolean starts With (String prefix)
It checks to see if the string has the prefix supplied; if so, it returns true; otherwise, it returns false.
Syntax:
boolean startsWith(String str);
- boolean starts With (String suffix)
Determines if the string contains the provided suffix at the end
Syntax:
public boolean endsWith(String suffix)
- int hashcode()
It gives back the string's hash code.
Syntax:
public int hashcode()
- int index of(int ch, int from index)
Similar to the index of the method, except it begins its search in the string at the from index value.
Syntax:
public in indexof(int ch, int fromIndex)
- int lastIndexOf(int ch)
It gives the string's final instance of the character char.
Syntax:
public int lastIndexOf(int ch, int fromIndex)
- int last Index Of(int ch, int from Index)
It begins searching from fromIndex, much like the lastIndexOf(int ch) method does.
Syntax:
public int lastIndexOf(int ch, int fromIndex)
- int index Of(String str)
The index of the very first existence of the specified substring str is provided by this function.
Syntax:
int indexOf(String str, int strt)
- int last index Of(String str)
Provides the last instance of string str's index.
Syntax:
public int lastIndexOf(String str)
- String substring(int begin Index)
It gives back the string's substring. The character at the supplied index is the first character of the substring.
Syntax:
substring(int beginIndex, int endIndex)
- String substring(int begin Index, int end Index)
The substring is given back. Character at begin Index is where the substring begins, and character at end Index is where it ends.
Syntax:
substring(int beginIndex, int endIndex)
- String Concat(String str)
Adds the "str" string that has been supplied at the end of the string
Syntax:
public String concat(String s)
- String to Lower Case():
It is equal to toLower Case or we can say Locale.getDefault().
Syntax:
public string toLowerCase()
- String trim()
Removes preceding and subsequent white spaces from the normal or genuine string before returning the substring.
Syntax:
public String trim()
- char[] to Char Array()
It will convert the string to a char array.
Syntax:
“char array_name[] = new char[array_length]”
- static String copy Value Of(char[] data)
Characters from the supplied character array are included in the resulting string.
Syntax:
static copyValueOf(char[] data)
- static String copy Value Of(char[] data, int offset, int count)
The same as the aforementioned technique, but with an additional beginning offset and additional sub-array length parameter
Syntax:
public static String copyValueOf(char[] data, int offset, int count
- static String value Of()
It is the string representation of the supplied inputs, including integer, long, float, double, character, and character array, that this function delivers.
- boolean content Equals(StringBuffer sb)
The string is compared to the designated string buffer.
Syntax:
public boolean contentEquals(StringBuffer sb)
- byte[] get Bytes(String char set Name)
It uses the supplied charset encoding to transform the String into a series of bytes and then returns the array of the resulting bytes.
Syntax:
public byte[] getBytes(String charsetName) throws UnsupportedEncodingException
- byte[] get Bytes()
This technique, which is identical to the one before, simply converts the string into a series of bytes using the default charset encoding.
Syntax:
public byte[] getBytes() public byte[] getBytes(Charset charset) public byte[] getBytes(String charsetName)throws UnsupportedEncodingException
- int length()
It Shows the length of a particular string
Syntax:
public int length()
- boolean matches(String regex)
- It determines if the String matches the designated regular expression regex.
Syntax:
public boolean matches(String regex)
- int code Point At(int index)
- In contrast to the charAt method, which returns the character itself, this function delivers the Unicode code point value for the supplied index.
Syntax:
public codePointBefore(char[] a, int index)
- String replace(char old Char, char new Char)
It replaces every instance of old Char with new Char, then returns the newly modified string.
Syntax:
public String replace(char oldChar, char newChar) public String replace(CharSequence target, CharSequence replacement)
- String to Upper Case(Locale locale)
According to the standards established by the supplied locale, transforms the string to the upper case.
Syntax:
public String toUpperCase(Locale locale)
- String to Upper Case()
It is equal to toUpper Case or we can say Locale.getDefault().
Syntax:
public toUpperCase()
- public String intern()
The supplied string is searched for in the memory pool using this method, and if it is located, its reference is returned; otherwise, memory space is allocated for the requested string, and its reference is given.
Syntax:
public String intern()
- public Boolean is Empty()
If the supplied string is zero in length, this function returns true. It returns false if the length of the given Java String is greater than zero.
Syntax:
public boolean isEmpty()
- public static String join()
This method concatenates the Java String after joining the provided strings together using the defined delimiter.
Syntax:
public static String join()
- String replace First(String regex, String replacement)
It substitutes the designated alternative string for the first instance of a substring that matches the provided regular expression "regex."
Syntax:
public String replaceFirst(String regex, String replacement)
- String replace All(String regex, String replacement)
It substitutes the alternative string for every instance of a substring that matches the regular expression regex.
Syntax:
public String replaceAll(String regex, String replacement)
- String[] split(String regex, int limit)
The string is divided, and it then produces an array of substrings that satisfy the specified regular expression. Limit serves as a cutoff for results here.
Syntax:
public String[] split(String regex, int limit)
- String[] split(String regex)
The function is identical to split(String regex, int limit), except it does not contain a threshold limit.
Syntax:
public String[] split(String regex)
- String to Lower Case(Locale locale)
It uses the rules established by the specified locale to transform the string to lower case
Syntax:
public toLowerCase(locale locale)
- public static String format()
This function gives a string that is in the right format.
Syntax:
public static String format()