String类的常用方法
public class StringDemo {
public static void main(String[] args) {
StringDemo sd = new StringDemo();
}
public void trimMethod(){
String str = " jack ";
System.out.println(str.length());
String trim = str.trim();
System.out.println(trim.length());
String url = "www.baidu.com";
char[] chars = url.toCharArray();
boolean empty = url.isEmpty();
System.out.println(empty);
byte[] bytes = url.getBytes();
System.out.println(Arrays.toString(bytes));
}
public void compareToMethod(){
String str = "a";
String str1 = "c";
int i = str.compareTo(str1);
System.out.println(i);
}
public void charAtMethod(){
String url = "http://www.sina.com.cn";
char index = url.charAt(1);
System.out.println(index);
String replace = url.replace(":", "*");
System.out.println(replace);
}
public void lowerUpCase(){
String str = "abcdEFGhEDfdf";
String upper = str.toUpperCase();
System.out.println(upper);
String lower = str.toLowerCase();
System.out.println(lower);
}
public void splitMethod(){
String str = "a,b,c,d,e,f,g,h";
String[] split = str.split(",");
String newStr = "";
for (int i = 0; i < split.length; i++) {
newStr+=split[i];
}
System.out.println(newStr);
}
public void subStringMethod(){
String url = "http://www.sina.com.cn";
String str = url.substring(7);
String str1 = url.substring(7,19);
System.out.println(str);
System.out.println(str1);
int index = url.indexOf("/");
System.out.println(index);
int index1 = url.lastIndexOf(".");
System.out.println(index1);
String url1 = url.substring(url.indexOf("/")+2,url.lastIndexOf("."));
System.out.println(url1);
}
public void containsMethod(){
String url = "http://www.baidu.com";
String url1 = "http://www.sina.com";
System.out.println(url.contains("//"));
System.out.println(url.startsWith("http://www.ba"));
System.out.println(url.endsWith(".com"));
}
public void equalsMethod(){
String str = "jack";
String str1 = "Jack";
System.out.println(str.equals(str1));
System.out.println("忽略大小写"+str.equalsIgnoreCase(str1));
}
}