3-数组与字符串说课.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
NCEPU String类 - 2.String类的常用方法 String substring (int beginIndex ) 返回从beginIndex开始的子串 System.out.println ( s1.substring ( 2 ) ); 例如: String s1 = Hello; llo String substring (int beginIndex, int endIndex) 返回从beginIndex开始到endIndex之前的子串 System.out.println ( s1.substring(2, 4) ); ll NCEPU String类 - 2.String类的常用方法 String replace ( char oldChar, char newChar ) 将字符串中所有的oldChar转换为newChar System.out.println ( s1.replace ( l, t)); 例如: String s1 = Hello; Hetto int indexOf(String str) 返回str在字符串中第一次出现的位置 System.out.println ( s1.indexOf ( ell) ); 1 NCEPU String类 - 2.String类的常用方法 String concat (String str) 将str连接在当前字符串的尾部 System.out.println ( s1.concat( World!)); 例如: String s1 = Hello; Hello World! NCEPU String类 - 2.String类的常用方法 boolean equals (String str ) 比较str与当前字符的内容是否相同 System.out.println ( s1.equals ( hello ) ); 例如: String s1 = Hello; false boolean equalsIgnoreCase (String str ) 比较str与当前字符的内容是否相同,并且忽略字符大小写 System.out.println(s1.equalsIgnoreCase (hello)); true NCEPU 0 若str和当前字符串仅长度不同,则返回两者长度的差值 System.out.println(pareTo(Hello World)); String类 - 2.String类的常用方法 int compareTo (String str ) 比较str和当前字符串的内容,返回差值 例如: String s1 = Hello; 若str和当前字符串相等,则返回0 System.out.println (pareTo (s1) ); -6 若str和当前字符串不相等,则返回第一个不同字符的差值 System.out.println ( pareTo (Hillo)); -4 NCEPU String类 - 3.= = 与 equals( )方法 equals ( ) 是判断两个String对象内容是否相同 = = 是判断两个String对象是否为同一实例,即在内存中的存储空间是否一致。 NCEPU class StringTest2 { public static void main (String args[ ]) { String s1 = This is the second string.; String s2 = This is the second string.; String s3 = new String (This is the second string.); String s4 = new String ( s1 ); String s5 = s1; 0s1 This is the second string. 0s1 This is the second string. 0s2 0s1 This is the second string. 0s2 0s3 This is the second string. 0s1 This is the second string. 0s2 0s3 This

文档评论(0)

挑战不可能 + 关注
实名认证
内容提供者

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

1亿VIP精品文档

相关文档