文档详情

Java程序设计精编教程第9章_常用实用类.ppt

发布:2017-05-09约9.37千字共24页下载文档
文本预览下载声明
《Java程序设计精编教程》 第9章 导读 §9.1 String类 §9.1.1 构造字符串对象 §9.1.2 String 类的常用方法 §9.1.3 符串与基本数据的相互转化 §9.1.4 对象的字符串表示 §9.1.5 字符串与字符、字节数组 §9.1.6 正则表达式及字符串的替换与分解 §9.2 StringBuffer类 §9.2.1 StringBuffer对象的创建 §9.2.2 StringBuffer类的常用方法 §9. 3 StringTokenizer类 §9.4 Date类 §9.4.1 构造Date对象 §9.4.2 日期格式化 §9. 5 Calendar类 §9. 6 Math和BigInteger类 §9.6.1 Math类 §9.6.2 BigInteger类 §9. 7 DecimalFormat类 §9.7.1 格式化数字 §9.7.2 将格式化字符串转化为数字 §9. 8 Pattern与Match类 §9.8.1 模式对象 §9.8.2 匹配对象 §9. 9 Scanner类 * 常用实用类 主要内容 String类 StringBuffer类 StringTokenizer类 Date类 Calendar类 Math与BigInteger类 DecimalFormat类 Pattern与Match类 Scanner类 java.lang包中的String类来创建一个字符串变量,字符串变量是对象。 1.常量对象:字符串常量对象是用双引号括起的字符序列,例如:你好、12.97、boy等。 2.字符串对象 声明:String s; String类较常用构造方法: String(s),String (char a[]),String(char a[],int startIndex,int count) 3.引用字符串常量对象 string s1 = how are you; 1.public int length():获取一个字符串的长度 2.public boolean equals(String s):比较当前字符串对象的实体是否与参数s指定的字符串的实体相同 例题9-1 3.public boolean startsWith(String s) public boolean endsWith(String s)方法:判断当前字符串对象的前缀(后缀)是否参数s指定的字符串 4. public int compareTo(String s):按字典序与参数s指定的字符串比较大小其相关方法 public int compareToIgnoreCase(String s) 例题9-2 5. public boolean contains(String s):判断当前字符串对象是否含有参数指定的字符串s 6. public int indexOf (String s):从当前字符串的头开始检索字符串s,并返回首次出现s的位置,其相关方法: indexOf(String s ,int startpoint), lastIndexOf (String s) 7. public String substring(int startpoint):获得一个当前字符串的子串 其相关方法:substring(int start ,int end) 8.public String trim() :得到一个s去掉前后空格后的字符串对象。 例题9-3 ◆java.lang包中的Integer类调用其类方法: public static int parseInt(String s) 可以将由“数字”字符组成的字符串,如12356,转化为int型数据,例如: int x; String s = 123456; x = Integer.parseInt(s); 类似地,使用java.lang包中的Byte、Short、Long、Float、Double类调相应的类方法可以将由“数字”字符组成的字符串,转化为相应的基本数据类型。 ◆可以使用String 类的类方法public static String valueOf(byte n)d等将形如123、1232.98等数值转化为字符串。 ◆可以使用Long类中的类方法public static String
显示全部
相似文档