JAVA - Some Java String Functions
____________________________________________________________________In this java Tutorial we will see Some String Methode In Java NetBeans .
Source Code:
package JavaDB_001;
public class Project {
public static void main(String[] args){
String str = "1bestcsharp.blogspot.com";
System.out.println("length: "+str.length());
System.out.println("indexOf: "+str.indexOf("."));
System.out.println("lastIndexOf: "+str.lastIndexOf("."));
System.out.println("startsWith: "+str.startsWith("1"));
System.out.println("endsWith: "+str.endsWith("m"));
System.out.println("compareTo: "+str.compareTo("1bestcsharp"));
System.out.println("compareTo: "+str.compareTo("1bestcsharp.blogspot.com"));
System.out.println("compareTo: "+str.compareTo("www.1bestcsharp.blogspot.com"));
System.out.println("equals"+str.equals(new String("1bestcsharp")));
System.out.println("toUpperCase: "+str.toUpperCase());
System.out.println("toLowerCase: "+str.toLowerCase());
System.out.println("trim: "+new String(" 1bestcsharp.blogspot.com").trim());
System.out.println("replace: "+str.replace("com", "net"));
}
}
/////// OUTPUT:
length: 24
indexOf: 11
lastIndexOf: 20
startsWith: true
endsWith: true
compareTo: 13
compareTo: 0
compareTo: -70
equalsfalse
toUpperCase: 1BESTCSHARP.BLOGSPOT.COM
toLowerCase: 1bestcsharp.blogspot.com
trim: 1bestcsharp.blogspot.com
replace: 1bestcsharp.blogspot.net