Back to: Java Program’s
0
public class StringDemo
{
static void main()
{
String str1="fridge";
String str2="emerald";
System.out.println("str1:"+str1);
System.out.println("str2:"+str2);
char chAt=str2.charAt(6);
System.out.println("str2.chAt(6) :"+chAt);
int compare=str1.compareTo("frid");
System.out.println("str1.compareTo(frid) :"+compare);
int comp1=str2.compareToIgnoreCase("EMERALD");
System.out.println("str2.compareToIgnoreCase(EMERALD);"+comp1);
String concat="mango".concat(" milkshake");
System.out.println("She wants "+concat);
boolean ends=str2.endsWith("rald");
System.out.println("str2.endsWith(rald) :"+ends);
boolean starts=str1.startsWith("eme");
System.out.println("str1.startsWith(eme) :"+starts);
int index=str2.indexOf('m');
System.out.println("str2.indexOf('m') :"+index);
boolean equal=str2.equals("Emerald");
System.out.println("str2.equals(Emerald) :"+equal);
String trims=" She loves emerald.".trim();
System.out.println(" She loves emerald..trim() :"+trims);
}
}
Submitted By: Ms. Suchetana Mukherjee
If this program was helpful to you, do leave a comment.
All Creadit goes to Ms. Suchetana Mukherjee
P.N. : All the post on this website are for demonstration and education purpose only.
Student should perform all the practicals for there personal copies.