There are no items in your cart
Add More
Add More
Item Details | Price |
---|
String Methods in Java Tutorial
Thu Jan 13, 2022
indexOf()
indexOf() method returns the position of the first occurrence of the specified character or string in a specified string.
Signature:
int indexOf(char ch)
int indexOf(String substring)
int indexOf(char ch, int fromIndex)
int indexOf(String substring, int fromIndex)
Example:
class First
{
public static void main(String[] args)
{
String S1="Welcome";
System.out.println(S1.indexOf('e'));
System.out.println(S1.indexOf('e',2));
System.out.println(S1.indexOf("co"));
System.out.println(S1.indexOf("co",6));
System.out.println(S1.indexOf('k')); //return -1 if char/substr not found
}
}
Output:
1
6
3
-1
-1
toLowerCase()
toLowerCase() method returns the string in lowercase letter i.e. it converts all characters of the string into lower case letter.
Signature
public String toLowerCase()
Example:
class First
{
public static void main(String[] args)
{
String S1="Welcome";
System.out.println(S1.toLowerCase() );
}
}
Output:
welcome
toUpperCase()
toUpperCase() method returns the string in uppercase letter i.e. it converts all characters of the string into upper case letter.
Signature
public String toUpperCase()
Example:
class First
{
public static void main(String[] args)
{
String S1="Welcome";
System.out.println(S1.toUpperCase() );
}
}
Output:
WELCOME
S P SHARMA CLASSES
S P SHARMA SIR