Vidoe14(ch3)

Yash
0

 



Program:-


https://drive.google.com/file/d/1bDNag0nqLLoBI-hLQUiMAbAem5c7Fv4j/view?usp=drivesdk



public class StringMethods {

public static void main(String[] args) {

String name = "Harry";

//1.name.length();

int length = name.length();

System.out.println("1.The length of String is :"+length);

//2.name.toLowerCase();

String lowercase = name.toLowerCase();

System.out.println("2.The Harry in lowercase is :"+lowercase);

//3.name.toLowerCase();

String uppercase = name.toUpperCase();

System.out.println("3.The Harry in uppercase is:"+uppercase);

//4.name.trim();

String nontrimmedstring = "        Harry      ";

System.out.println("4.The non trimmed string is :"+ nontrimmedstring);

String trimmedstring = nontrimmedstring.trim();

System.out.println("The trimmed string is : "+trimmedstring);

//5.name.substring(int Start)

System.out.println("5.The substring from index 1 in a given string Harry is : "+name.substring(1));

//6.name.subatring(int start, int end)

System.out.println("6.The substring form index 1 to 4 in a given string Harry is : "+ name.substring(1,5));

//7.name.replace(oldChar:'r', newChar:'p');

System.out.println("7. If we replace the\'r\' from the string Harry by \'p\' then resultant string is :"+name.replace('r', 'p'));

//8.name.startWith("Ha");

System.out.println("8.Is that the given string starts with \"Ha\"  :"+name.startsWith("Ha"));

//9.name.endsWith();

System.out.println("9.Is that the given string ends with \"ry\": "+name.endsWith("ry"));

//10.name.charAt(2);

System.out.println("10.The character at the index number 2 is :"+ name.charAt(2));

System.out.println("The character at the index number 0 is :"+name.charAt(0));

//11.name.indexOf(string);

String modifiedName = "Harryrry";

System.out.println("11.The index number of \'rry\' is :"+modifiedName.indexOf("rry"));

//12.name.indexOf("string",3);

System.out.println("12.The index number of \'rry\' after index 4 is :"+modifiedName.indexOf("rry",4));

//otherwise 

System.out.println("The index number of \'rry5676\'' is:"+ modifiedName.indexOf("rry5676"));

//13.name.lastIndexOf("rry");

System.out.println("13.The index number of \'rry\' form the last is :"+modifiedName.lastIndexOf("rry"));

//14.name.lastIndexOf("rry",2)

System.out.println("14.The index number of \'rry\' form the last when string is limited to index number 4 is  :"+modifiedName.lastIndexOf("rry",4));

//15.name.equals("Harry");

System.out.println("15.Is that the given string is equal to string \'Harry\' :"+name.equals("Harry"));

//16.name.equalsIngnoreCase("harry");

System.out.println("16.Is that the given string is equal to string \'harRy\' ignore the letter is capital or not :"+ name.equalsIgnoreCase("harRy"));

}

}

Tags

Post a Comment

0 Comments
Post a Comment (0)
To Top