×

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()

Related Topics

Advantages and Disadvantages of Strings in Java

What is a String? Java is an object-oriented, platform-independent, high-level, general-purpose, and interpreted programming language.Sun Microsystems is known as the founder of java in 1991; the Java programming language was developed...

4 minutes read.

Java Boolean logicalAnd() Method

The logicalAnd() method of Java Boolean class returns the result of implementing logicalAND operation on the specified Boolean operands. Syntax:public static boolean logicalAnd (boolean a, boolean b) Parameters:The parameters ‘a’ and ‘b’...

2 minutes read.

Alice and Bob Problem Java

Alice and Bob were two friends who liked to play games. Both together found a game, which has the description below. The game begins with an integer num, used to create...

2 minutes read.

Java Math.multiplyExact() method

In java, we are provided with multiplyExact method in the Math module. This Math module belongs to the java.lang package. In general, this method returns the product of the provided...

2 minutes read.

Java List Node

In Java, List Node is the same as the single linked list, which is the collection of nodes. So, we can say, the list nodes are grouped together to get...

8 minutes read.

Java time local date

Java: Java is one of the programming language which is object oriented. It consists of many features such as robust, simple, architecture neutral, dynamic, distributed, multi threaded, portable etc. The main feature...

3 minutes read.

Java Math max() Method

The max() method of Math class returns the greater of two arguments. The arguments can be of double, float, int or long data type. Syntax: public static double max(double a, double b)public...

2 minutes read.

Java Exception Propagation

Java Exception Propagation When an exception is being thrown from the peak of the stack and not getting caught, it runs down the stack to the previous method, which is sitting...

3 minutes read.

HashMap Vs HashTable

HashMap HashMap is the basic implementation of the map interface in Java. HashMap stores the data in key and value pairs. Keys are used to access the value of the element. It...

5 minutes read.

Chromatic Number in Java

The chromatic number is the bare minimum of colours necessary to accurately colour any graph. To put it another way, the chromatic number can be thought of as the bare...

6 minutes read.

How to Convert Hexadecimal to Decimal in Java

How to Convert Hexadecimal to Decimal in Java There are two methods to convert Hexadecimal to Decimal: Using parseInt() method Using user-defined logic Using Integer.parseInt() method It is a static method of...

2 minutes read.

How to sort a String in Java

Sorting is the process of putting the elements in a certain order, either ascending or descending. Mostly the alphabetical order or natural order is used for a string. In other...

5 minutes read.

Difference between Abstract Class and Interface

There is a similarity between abstract class and interface is that we cannot create objects for both of them. But irrespective of this, there are some differences between them, let’s...

2 minutes read.

Java Int Keyword

Among the primitive data types is the Java int keyword. To declare variables, use this. It can also be used with methods that return values of the integer type. It...

3 minutes read.

Java Code Optimization

We encounter the idea of optimization while working on any Java application. It is essential that the code we write is not only clear and error-free but also optimized, meaning...

9 minutes read.

How to Convert Timestamp to Date in Java

How to Convert Timestamp to Date in Java You can convert Timestamp to Date by using the constructor of Date class. It returns the long millisecond from Epoch (1st January 1970)...

2 minutes read.

Three-way operator in Java

The ternary operator in Java is the only conditional operator that takes three operands. It's a popular one-line substitute for the if-then-else expression among Java programmers. If-else clauses can be...

3 minutes read.

Minimum Lights to Activate Java Snippet Class

Minimum Lights to Activate Problem in Java In prison, there is a hallway that is N units long. Given an N-dimensional array A. If the light at the ith position is...

3 minutes read.

Java Math tanh() Method

The tanh() method of Java Math class returns the hyperbolic tangent of the specified double value. Syntax: public static double tanh(double x) Parameters: The parameter ‘x’ represents the number whose hyperbolic tangent is to...

2 minutes read.

Java Math copySign() Method

The copySign() method of Math class returns the first floating-point argument with the sign of the second argument. Syntax: public static float copySign(float magnitude, float sign)public static double copySign(double magnitude, double sign) Parameters: The...

1 minute read.