×

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

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.

Interchange Diagonal elements in Java

In this article, you will be very well acknowledged about what is a matrix with an example. You will also be acknowledged about how to interchange the diagonal elements in...

4 minutes read.

Read the XLSX file in Java

Excel files contain cells; reading an excel file in Java differs from reading a word file. JDK doesn't have a direct API that can read or write Word or Excel...

3 minutes read.

Java Identifiers

In Java, the symbolic notations used for identification are called identifiers. Identifiers can be the name for the class, variable name declaration, name of the package, constant name and many...

3 minutes read.

Nested Enum in Java

A class that can be defined within another class is called a nested class in Java. You can logically group classes that are used onlyin one place. This makes encapsulation...

3 minutes read.

Root exception in java

Java: The main feature of java which is not in C or object oriented programming language is platform independence. Not only the platform independence there are many other features in java...

3 minutes read.

Short Circuit Logical Operators in Java

When there are two or more relational expressions in a decision-making statement, logical operators are utilized to combine them. The logical operators short circuit and not-short circuit fall into two...

5 minutes read.

How to Set Environment Variables for Java

Introduction Java is an object-oriented programming language that is based on classes and can be employed mostly to develop web and desktop applications. No matter the computer architecture, Java applications are...

7 minutes read.

Java Regular Expressions

Java Regular Expressions The Java Regex or Regular Expression is an API that defines a pattern for searching or manipulating strings. A regular expression is a pattern that can be as simple as...

8 minutes read.

Pangram Program in Java

If a string comprises all alphabet letters from A to Z or from a to z without regard to case, it is referred to as a pangram. Some examples of pangram...

3 minutes read.

Java Variable Declaration

In this article, you will be acknowledged about java variable declaration. You will be able to learn and interpret about declaring a variable in Java. Variable in Java Variables are necessary for...

6 minutes read.

Economical number in Java

Economical number is said to be economically efficient if the number of digits after prime factorization of the original number with their powers is less than the number of digits...

3 minutes read.

ArrayList Program in Java

ArrayList Program in Java: In Java, ArrayList is a class that belongs to java.util package. It is the dynamic list that grows or shrinks at run-time as per the requirements....

4 minutes read.

Collection Interfaces in Java with Examples

In this tutorial, we will discuss collection interfaces in Java with Examples. Introduction The Collection Interface is an individual from the Java Collections Framework. It is a root point of interaction of...

4 minutes read.

How to Convert char to int in Java

How to Convert char to int in Java When two variables of different types are involved in the single expression, Java compiler uses built-in library function to convert the variable to...

3 minutes read.

Tetranacci Number in Java

This article mainly describes tetranacci number identification and the Java Program for Tetranacci numbers. Tetranacci number Tetranacci numbers and Fibonacci numbers are related. The key contrast is that a Tetranacci number depends...

3 minutes read.

Java Code Coverage Tools

Code coverage testing is a crucial metric that gauges how thoroughly the program's source code has been tested. The market is flooded with Code Coverage Tools, making it difficult to...

7 minutes read.

How to Develop Programming Logic in Java?

Introduction In the world of software development, Java programming language is one of the most powerful programming languages that is used to create a wide range of applications. It includes desktop,...

18 minutes read.

Convert milliseconds to date in Java

In Java, we frequently need to convert milliseconds into Dates with several formats, including dd MM yyyy and dd MM yyyy HH:mm:ss:SSS Z, among others. The Date class is one of the most...

4 minutes read.

Literals in Java

In this article we acknowledge ourselves about the term literals in java, types of literals and an example to each of them. Literal Literal refers to any constant value that can be...

4 minutes read.