第9章常用实用类 王绍卿
1 第9章 常用实用类 王绍卿
导读 主要内容 ●String类 ●String Tokenizer类 ● Scanner类 ● Date类 ●Clendar类 ● Math与BigInteger类 ● DecimalFormat类 ● Pattern与Match类 难点 ●Pattern与Match类 ● Scanner类
2 导读 主要内容 ● String类 ● StringBuffer类 ● StringTokenizer类 ● Scanner类 ● Date类 ● Clendar类 ● Math与BigInteger类 ● DecimalFormat类 ● Pattern与Match类 难点 ● Pattern与Match类 ● Scanner类
§9.1 String类 String类在java.lang包中。String类用来 创建一个字符串变量,字符串变量是对象
3 §9.1 String类 String类在java.lang包中。String类用来 创建一个字符串变量,字符串变量是对象
§9.1.1构造字符串对象1 1.常量对象:字符串常量对象是用双引号括起的字符 序列,例如:"你好"、"12.97"、"boy"等。 2.字符串对象 ◆声明:String s; ◆创建字符串对象:s=new String("we are students'"); 或者用一个已创建的字符串创建另一个字符串,例如: String tom=String(s); String类较常用构造方法: String(char a) String(char a,int startIndex,int count) 2025/4/2
2025/4/2 4 §9.1.1 构造字符串对象 _1 1.常量对象:字符串常量对象是用双引号括起的字符 序列,例如:"你好" 、 "12.97" 、 "boy"等。 2.字符串对象 ◆声明:String s; ◆ : s=new String("we are students"); String tom=String(s); String : String(char a[]) String(char a[], int startIndex, int count)
§9.1.1构造字符串对象2 3.引用字符串常量对象 string s1,s2; s1 "how are you"; s2 "how are you"; 这样,s1,s2具有相同的引用,因而具有相同的实体。 sl 0xAb28 How are you 0xAb28 s2 图91内存示意图
5 §9.1.1 构造字符串对象_2 3.引用字符串常量对象 string s1,s2; s1 = "how are you"; s2 = "how are you"; s1,s2