String class methods examples
concat() and replace() methods example
toLowerCase() and toUpperCase() methods
String in proper case methods
split() method example
concat() and replace() methods example
import java.util.Scanner;
public class StringDemo
{
public static void main(String[] args)
{
String x = "abc";
String y = x.concat("Cef").replace('a', 'z');
System.out.println(y);
}
}
Output
zbcCef
toLowerCase() and toUpperCase() methods
toLowerCase() and toUpperCase() methods
import java.util.Scanner;
public class StringDemo
{
public static void main(String[] args)
{
System.out.println("enter the string = ");
String a=new Scanner(System.in).nextLine();
System.out.println(a+" in upper case = "+a.toUpperCase());
System.out.println(a+" in lower case = "+a.toLowerCase());
}
}
Output
enter the string = jtechies jtechies in upper case = jtechies jtechies in lower case = jtechies
String in proper case methods
String in proper case methods
import java.util.Scanner;
public class StringDemo
{
public static void main(String[] args)
{
System.out.print("enter the string = ");
String a=new Scanner(System.in).nextLine();
System.out.print(a+" in proper case = ");
String temp=a;
String arr[]=a.split(" ");
for(String z:arr)
{
System.out.print(String.valueOf
(z.charAt(0)).toUpperCase()
+z.substring(1).toLowerCase());
}
}
}
Output
enter the string = jtechies jtechies in proper case = jtechies
split() method example
split() method example
import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
System.out.print("enter the string = ");
String a=new Scanner(System.in).nextLine();
System.out.println(a+" split by comma(,)");
String arr[]=a.split(",");
for(String z: arr)
{
System.out.println(z);
}
String c=a+" hello";
System.out.println(c.concat(" bye"));
}
}
Output
enter the string = jtechies,jtechies jtechies,jtechies split by comma(,) jtechies jtechies jtechies,jtechies hello bye


