- 1、本文档共66页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 Objectives To use the String class to process fixed strings To use the Character class to process a single character To use the StringBuffer class to process flexible strings To learn how to pass strings to the main method from the command line To discover file properties, delete and rename files using the File class To write data to a file using the PrintWriter class To read data from a file using the Scanner class Introduction(P262 8.1) String are used often in programming. A String is a sequence of characters. In many language ,strings are treated as array of characters, but in Java a string is an Object. Strings Are Immutable(8.2.2) A String object is immutable; its contents cannot be changed. Does the following code change the contents of the string? String s = Java; s = s + HTML; Construct a String (1) To creating a string from a string literal (2) Since strings are used frequently, Java provides a shorthand initializer for creating a string: (3) Create a string from an array of characters Interned Strings String s1 = new String(welcome to java); String s2 = new String(welcome to java); System.out.println(s1==s2); Interned Strings(8.2.2) Since strings are immutable and are frequently used, to improve efficiency and save memory, the JVM uses a unique instance for string literals with the same character sequence. Such an instance is called interned. You can also use a String object’s intern method to return an interned string. Examples(8.2.2) Display: s1 == s is false s2 == s is true s == s3 is true Finding String Length(8.2.4) Definition: public int length() Retrieving Individual Character(8.2.4) Definition : public char charAt(int?index) Exercise 1 输入任意字符串,将其反向输出 Scanner input = new Scanner(System.in); String s = input.next(); 反向输出s Exercise 2(P270 listing8.1) 判断一个字符串是不是回文(palindrome)
您可能关注的文档
- Java 2实用教程课件(第3版第1章 Java 语言入门).ppt
- Java 2实用教程课件(第3版第4章 类、对象和接口).ppt
- Java 2实用教程课件(第3版第4章).ppt
- Java 2实用教程课件(第3版第5章 字符串).ppt
- Java 2实用教程课件(第3版第5章).ppt
- Java 2实用教程课件(第3版第6章).ppt
- Java 2实用教程课件(第3版第8章).ppt
- Java 2实用教程课件(第3版第9章).ppt
- Java 2实用教程课件(第3版第10章).ppt
- Java 2实用教程课件(第3版第13章).ppt
- DB23_T 3866-2024冰上龙舟赛事组织服务规范.docx
- DB32 2163-2012 棉纱单位可比综合电耗限额及计算方法.docx
- DB32∕T 2429-2013 棉花田间生长发育观察记载规范.docx
- DB23_T 3820-2024 工业互联网综合平台数据质量管理规范.docx
- DB23_T 3474-2023非煤智慧矿山信息系统技术规范.docx
- DB3201_T 1106-2022 工程地质层划分技术规范.docx
- DB33T 2515-2022公共机构“零碳”管理与评价规范.docx
- DB3301_T 0415-2023 装修垃圾收运处置管理规范.docx
- DB3311/T 106―2019“丽水山居”民宿服务要求与评价规范.docx
- DB3201T 1127-2022 慈善捐赠受赠管理规范.docx
最近下载
- 铁塔室外光电一体箱(技术规范书)-.docx VIP
- 铂科磁材在太阳能逆变器的应用.pdf VIP
- 2025·上海浦东新区·二模智慧藏于“笨办法”:慢工出细活的真谛+审题立意及范文-备战2025年中考语文各地名校模考卷作文导写.docx VIP
- 经血源传播疾病的医院预防控制措施.docx VIP
- 安全操作规程(全套).doc VIP
- (word完整版)苏州工业园区合格证第四版参考题库答案.pdf VIP
- 2025年北京市通州区中考一模从“乐在其中”悟人生真谛”审题立意及范文-备战2025年中考语文各地名校模考卷作文导写.docx VIP
- 2021版 客户侧电能计量装置通用设计要求 第1部分 10kV用电客户电能计量装置.docx VIP
- Q∕SYCQ 4008-2022 工业用液化轻烃原料(打印版).pdf VIP
- 租房合同范本(完美打印版)6篇 .pdf VIP
文档评论(0)