×

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

Bin Packing Problem Java

Assigning some items with known weights to bins with consistent capacities is necessary for the bin packing problem. The goal is to use the smallest possible boxes while ensuring everything is put...

6 minutes read.

XNOR operator in Java

The opposite of the binary equivalent of XOR is given by XNOR. Truth table: XYXNOR001010100111 If the bits are the same, it returns 1, else it returns 0. Examples:  Input: 10 20 Output : 1 A Binary...

3 minutes read.

String Programs in Java

String Programs in Java: In Java, a String is an immutable object that represents a sequence of characters. For example, “Tutorial” is a string that consists of 8 characters: ‘T’,...

10 minutes read.

Java Try-Catch Block

Java Try Block The handling of the exceptions in a block of code is done with the help of java try block. It throws the code that is enclosed in a...

3 minutes read.

Compile time vs Runtime in java

Introduction: This article will discuss compile time vs. runtime in java. Compile time and runtime are two programming terms utilized in software improvement. Compile time is when the source code is...

3 minutes read.

Interfaces and Classes in Strings in Java

CharBuffer: CharBuffer is utilized to implement the CharSequence interface. With the help of the mentioned class, we can allow character buffers to be utilized instead of CharSequences. We can consider the illustration...

4 minutes read.

Types of Logical Operators in Java

In this tutorial, we are going to study logical operators. A logical operator is an operator that accomplishes a logical operation that is to connect two or more operations. These...

5 minutes read.

How to create array of objects in Java

Java is an object-oriented programming language therefore everything in Java is based on objects and classes. Array is a data structure that holds data of similar type and dynamically creates...

4 minutes read.

Zebra Puzzle Problem in Java

Complex puzzles like the zebra puzzle demand a lot of work and mental training to complete. Because it was created by renowned German scientist Albert Einstein, it is also sometimes...

10 minutes read.

flour pack problem in Java

Create a method called canPack and give it three int parameters: bigCount, smallCount, and objective. The bigCount option indicates the number of large flour bags (5 kilos each). The smallCount argument indicates...

3 minutes read.

Practical Number in Java

In this tutorial, we will understand what is meant by practical numbers. We will understand it throughthe aid of examples and implementation in a java programming language. The practical numbers...

5 minutes read.

Java Implements Keyword

To understand about the keyword implements we need to learn about the concept of the interfaces and inheritance in java programming languages. So let us learn about the interface and...

3 minutes read.

Upcasting and Downcasting in Java

Type casting in Java is an important and very interesting topic to deal with. But here upcasting and downcasting is somewhat related to typecasting. In normal typecasting, we convert from...

6 minutes read.

How to Run Applet Program in Java

An applet is a new type of program which is put in a webpage. By inserting applet into a webpage dynamic content can be created. Characteristics of an Applet The applet is...

11 minutes read.

Java Float Keyword

Float: In general, there are two categories of data types: primitive data types and non-primitive data types. So, float is the data type which is a primitive data type. Declarating the variables and...

3 minutes read.

Java Try Resource

In Java, a try argument that specifies one or more resources is known as a try-with-resources statement. When your program is finished utilizing an object, it must be closed, which...

4 minutes read.

Nth node from the end of the Linked list in Java

In talks with leading IT organizations like Google, Amazon, TCS, Accenture, etc., this extremely intriguing subject is constantly brought up. The goal of the problem-solving exercise is to evaluate the...

6 minutes read.

Maximum length of string in java

In java, String can act as a data type and a class. The string can be defined as the collection of characters that are enclosed with double quotes(“ “). The...

3 minutes read.

Java Program to print even and odd numbers using 2 threads

Using two threads in a single thread is even odd printing in Java programming with multiple threads. To create code that prints even and odd using two threads, we must...

2 minutes read.

Java Program to generate binary numbers

A binary tree can create binary numbers ranging from 1 to n. Every node in a tree, the right, and left nodes, has two children, as is common knowledge. The...

3 minutes read.