- 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
- 西北工业大学附属中学2025届九年级下学期中考七模数学试卷(含解析).docx
- 广西壮族自治区2025届九年级下学期中考三模数学试卷(含解析).docx
- 海珠湾隧道上盖综合体项目概念设方案.pdf
- 三年级数学下册(人教版)教学课件:我们的校园.ppt
- 忍一时风平浪静退一步海阔天空.pptx
- 人教英语必修三-第四单元名师公开课获奖课件百校联赛一等奖课件.pptx
- 女娲补天故事带精美图公开课获奖课件省赛课一等奖课件.pptx
- 文本案例ntz0 xx spanish liture paper 2 markscheme西牙.pdf
- slam理论详解附源码参考书中文字幕与cheatsheet.pdf
- 综合四大笔试questions.pdf
文档评论(0)