String Functions In Java

Hello, dear's today i am going to explain the different functions of the java string , which will help you to understand the java string better.
There are so many functions, but we will study those functions which are very frequently used in out coding.
Here we will discuss 25 different functions of the java string.
1) charAt():
It returns the character of the specified index. The index is starting from 0 and the last index is , length of the string-1.
Example 1:
public class Main {
public static void main(String[] args) {
String str="hello"; //Here the length is 5 , the indices are 0,1,2,3,4
System.out.println(str.charAt(0));
}
}
Output: h
Example 2:
public class Main { public static void main(String[] args) { String str="hello"; //Here the length is 5 , the indices are 0,1,2,3,4 System.out.println(str.charAt(4)); } }
Output: o
Example 3:
public class Main {
public static void main(String[] args) {
String str="hello"; //Here the length is 5 , the indices are 0,1,2,3,4
System.out.println(str.charAt(5));
}
}
it will give the StringIndexOutOfBoundsException , because we want to access index 5 which is not available.
Output: StringIndexOutOfBoundsException
Subscribe to my newsletter
Read articles from Chintamani Pala directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Chintamani Pala
Chintamani Pala
I am a full-stack developer based in Odisha, India. I am very passionate programmer and web developer pursuing a bachelor's degree in computer science and engineering from GIET University, Gunupur.