String class function
substring() method
String substring() method returns a part of the string. substring() method has two
override methods.
1. public String substring(int begin);
2. public String substring(int begin, int end);
The first argument represents the starting point of the subtring. If the substring()
method is called with only one argument, the subtring returns characters from
specified starting point to the end of original string.
If method is called with two arguments, the second argument specify the end
point of substring.
public class Demo {
public static void main(String[] args) {
String str = "0123456789";
System.out.println(str.substring(4));
System.out.println(str.substring(4,7));
}
}
Output
, 456789
456
toLowerCase() method
String toLowerCase() method returns string with all uppercase characters
converted to lowercase. public class Demo {
public static void main(String[] args) {
String str = "ABCDEF";
System.out.println(str.toLowerCase());
}
}
Output
Abcdef
toUpperCase() method
This method returns string with all lowercase character changed to uppercase.
public class Demo {
public static void main(String[] args) {
String str = "abcdef";
System.out.println(str.toUpperCase());
}
}
Output
Abcdef
substring() method
String substring() method returns a part of the string. substring() method has two
override methods.
1. public String substring(int begin);
2. public String substring(int begin, int end);
The first argument represents the starting point of the subtring. If the substring()
method is called with only one argument, the subtring returns characters from
specified starting point to the end of original string.
If method is called with two arguments, the second argument specify the end
point of substring.
public class Demo {
public static void main(String[] args) {
String str = "0123456789";
System.out.println(str.substring(4));
System.out.println(str.substring(4,7));
}
}
Output
, 456789
456
toLowerCase() method
String toLowerCase() method returns string with all uppercase characters
converted to lowercase. public class Demo {
public static void main(String[] args) {
String str = "ABCDEF";
System.out.println(str.toLowerCase());
}
}
Output
Abcdef
toUpperCase() method
This method returns string with all lowercase character changed to uppercase.
public class Demo {
public static void main(String[] args) {
String str = "abcdef";
System.out.println(str.toUpperCase());
}
}
Output
Abcdef