There are no items in your cart
Add More
Add More
Item Details | Price |
---|
length(), charAt()
Thu Jan 13, 2022
length()
length() method finds the length of a string i.e. the total number of characters present in the string.
Syntax
public int length();
String s1="Hello";
String s2="Java";
System.out.println("string length is: "+s1.length());
System.out.println("string length is: "+s2.length());
Output:
string length is: 5
string length is: 4
charAt()
charAt() method returns a char value at the given index number. The index number starts from 0 and goes to n-1, where n is the length of the string. It returns StringIndexOutOfBoundsException, if the given index number is greater than or equal to this string length or a negative number.
Syntax
public char charAt(int index);
String name="Welcome";
char ch=name.charAt(3);
System.out.println(ch);
Output:
c
S P SHARMA CLASSES
S P SHARMA SIR