package com.neusoft.constant;
/**
*Java中定义了String与StringBuffer两个类来封装对字符串的各种操作
String类与StringBuffer类都被放到了java.lang包中
两者的主要区别在于
String类对象中的内容初始化不可以改变
StringBuffer类对象中的内容可以改变
*/
import java.util.Date;
public class TestStringBuffer {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("abc");
sb.append("defg");
System.out.println(sb);//字符串的追加 abcdefg
sb.insert(3, "---");
System.out.println(sb);//abc---defg
sb.reverse();
System.out.println(sb);//gfed---cba
sb.append(new Date());
System.out.println(sb);//gfed---cbaTue Apr 03 09:43:12 CST 2018
String sql = "select * from EMP";//连接where用append
}
}
package com.neusoft.constant;
public class StringDemo {
public static void main(String[] args) {
String school = "neusoft";
String ss = " asdfghjkl ";
String newString = school.concat("ads");
System.out.println(newString.length());//10
System.out.println(newString.toUpperCase());//NEUSOFTADS
System.out.println(newString.substring(2));//usoftads
System.out.println(ss.valueOf(1));//1
System.out.println(ss.trim());//asdfghjkl
String ss1 = "boo<and<foo";
String[] array = ss1.split("o");
for(int i = 0;i<array.length;i++){
System.out.println(array[i]);
}
String str1 = new String("asd");
String str2 = new String("asd");
System.out.println(str1);
System.out.println(str2);
System.out.println(str1==str2);//false
System.out.println(str1.equals(str2));//true
//String 重写 equals 方法 比较结果为true
Integer integer1 = new Integer(10);
Integer integer2 = new Integer(10);
System.out.println(integer1 == integer2);//false
System.out.println(integer1.equals(integer2));//true
//封装类 重写equals方法
}
}