Stringhandling in java

class Stringhandling {
public static void main(String args[])
{
String s ="I LOVE LOVE";
System.out.println(s);//DISPLY THE STRING
System.out.println(s.length());// DISPLAY NO. OF CHAR
System.out.println(s.toUpperCase());//CONVERSION TO CAPITAL LETTERS
System.out.println(s.toLowerCase());//CONVERSION TO SMALLER LETTERS
System.out.println(s.startsWith("i"));//CHECKING STRING WHERTHER IT START WITH I OR NOT(CASE SENSITIVE)
System.out.println(s.endsWith("I"));//CHECK STRING END WITH I OR NT CASE-SENSITIVE
System.out.println(s.replace('O','h'));//REPLACE 'O' TO 'h' (CASE -SENSITIVE)
System.out.println(s.trim());//REMOVE UNUSED SPACES FROM CORNER
System.out.println(s.indexOf('O'));//DISPLAY POSITION OF CHARACTER FROM BEGINNING
System.out.println(s.lastIndexOf('O'));//DISPLAY POSITION OF CHARACTER FROM BEGINNING & IF CHAR NOT PRESENT THEN ANS= -1.
System.out.println(s.charAt(7));//DISPLAY CHAR WHICH IS AT 7th POSITION FROM BEGINNING
System.out.println(s.substring(2));// DISPLAY CHARACTER FROM 2nd POSITION TO LAST
System.out.println(s.substring(2,7));//DISPLAY CHARACTER FROM 2nd position to 7th where counting start from zero position(ANS LOVE)
String s2 ="I LOVE love";
System.out.println(s.startsWith(s2));// CHECK FROM BEGINNING TO END THE MATCH OF EACH WORD (here ans false 'coz case does not match)
System.out.println(s.equals(s2));//COMPARE ALL CHARACTER (CASE SENSITIVE)
System.out.println(s.equalsIgnoreCase(s2));// COMPARE BUT NOT CASE-SENSITIVE
}
}

No comments:

Post a Comment