indexOf(), toLowerCase(), toUpperCase() method of String in Java

String Methods in Java Tutorial

{{DATE}}

indexOf(), toLowerCase(), toUpperCase() 

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

{{AUTHOR}}
S P SHARMA SIR