第五节 常用类.ppt

  1. 1、本文档共25页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第五章 常用类 本章内容 数 组 字符串相关类( String、StringBuffer) 基本数据类型包装类 Math类 日期时间类 容器类 String 类 java.lang.String 类代表不可变的字符序列。 “xxxxx”为该类的一个对象。 String 类的常见构造方法: string(String original) 创建一个String对象为original 的拷贝。 String(char[] value) 用一个字符数组创建一个String对象 String(char[] value, int offset, int count) 用一个字符数组从offset项开始的count个字符序列创建一个String对象。 String 类举例 public class Test { public static void main(String[ ] args) { String s1=“hello”; String s2=“world”; String s3=“hello”; System.out.println(s1==s3); //true s1=new String (“hello”); s2=new String(“hello”); System.out.println(s1==s2); //false System.out.println(s1.equals(s2)); //true char c[ ]={‘s’,’u’,’n’,’ ‘,’j’,’a’,’v’,’a’}; String s4=new String(c); String s5=new String(c,4,4); System.out.println(s4); //sun java System.out.println(s5); //java String 类常用方法(1) public char charAt( int index) 返回字符串中第 index 个字符。 public int length( ) 返回字符串的长度 public int indexOf( String str) 返回字符串中出现 str 的第一个位置 public int indexOf( String str, int fromIndex) 返回字符串中从fromIndex开始出现str的第一个位置 public boolean equalsIgnoreCase( String another) 比较字符串与another 是否一样(忽略大小写) public String replace(char oldChar, char newChar) 在字符串中用newChar字符替换oldChar字符 String 类举例(2) String 类举例(3) String 类常用方法 (2) public boolean startsWith( String prefix) 判断字符串是否以prefix字符串开头 public boolean endsWith( String suffix) 判断字符串是否以suffix字符串结尾 public String toUpperCase( ) 返回一个字符串为该字符串的大写形式 public String toLowerCase( ) 返回一个字符串为该字符串的小写形式 public String substring( int beginIndex) 返回该字符串从beginIndex开始到结尾的子字符串 public String substring( int beginIndex, int endIndex) 返回该字符串从beginIndex开始到endIndex结尾的子字符串 public String trim( ) 返回该字符串去掉开头和结尾空格后的字符串 String 类常用方法 (3) 静态重载方法 public static String valueOf(…) 可以将基本类型数据转换为字符串;例如: public static String valueOf(double d) public static St

文档评论(0)

kehan123 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档