java语言程序设计-基础篇--第八版--英文课件(第9章).ppt

java语言程序设计-基础篇--第八版--英文课件(第9章).ppt

  1. 1、本文档共58页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
java语言程序设计-基础篇--第八版--英文课件(第9章)

Convert Character and Numbers to Strings The String class provides several static valueOf methods for converting a character, an array of characters, and numeric values to strings. These methods have the same name valueOf with different argument types char, char[], double, long, int, and float. For example, to convert a double value to a string, use String.valueOf(5.44). The return value is string consists of characters ‘5’, ‘.’, ‘4’, and ‘4’. * Problem: Finding Palindromes Objective: Checking whether a string is a palindrome: a string that reads the same forward and backward. * CheckPalindrome Run The Character Class * Examples Character charObject = new Character(b); charOpareTo(new Character(a)) returns 1 charOpareTo(new Character(b)) returns 0 charOpareTo(new Character(c)) returns -1 charOpareTo(new Character(d) returns –2 charObject.equals(new Character(b)) returns true charObject.equals(new Character(d)) returns false * Problem: Counting Each Letter in a String This example gives a program that counts the number of occurrence of each letter in a string. Assume the letters are not case-sensitive. * CountEachLetter Run StringBuilder and StringBuffer The StringBuilder/StringBuffer class is an alternative to the String class. In general, a StringBuilder/StringBuffer can be used wherever a string is used. StringBuilder/StringBuffer is more flexible than String. You can add, insert, or append new contents into a string buffer, whereas the value of a String object is fixed once the string is created. * StringBuilder Constructors * Modifying Strings in the Builder * Examples stringBuilder.append(Java); stringBuilder.insert(11, HTML and ); stringBuilder.delete(8, 11) changes the builder to Welcome Java. stringBuilder.deleteCharAt(8) changes the builder to Welcome o Java. stringBuilder.reverse() changes the builder to avaJ ot emocleW. stringBuilder.replace(11, 15, HTML) changes the builder to Welcome to HTML. stringBuilder.setCharAt(0, w) sets the builder to wel

文档评论(0)

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

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

1亿VIP精品文档

相关文档