Presentation is loading. Please wait.

Presentation is loading. Please wait.

第九章 字符串.

Similar presentations


Presentation on theme: "第九章 字符串."— Presentation transcript:

1 第九章 字符串

2 本章要点 一、字符串的概念 二、字符串对象的创建 1、创建String 对象 2、创建StringBuffer对象

3 字符串的概念 字符串是内存中连续排列的一个或多个字符,不是字符数组。
字符串在Java语言中提供了String和StringBuffer两个类来实现。  String类用于处理那些值不会发生改变的字符串 StringBuffer类用于那些可能发生变化的字符串处理

4 对象的创建 1、创建String对象: String str=“ABC”;
String str=new String( ); str=“ABC”; char[ ] helloArray=[‘h’,’e’,’l’,’l’,’o’]; String helloString=new String(helloArray); 2、创建StringBuffer对象: StringBuffer( ) StringBuffer(int length) StringBuffer(String str)

5 String的常用方法(一) public int length( ) public char charAt( int index )
public void getChars( int srcBegin,int srcEnd,char[] dst,int dstBegin) public boolean equals(Object other) public int compareTo(String anotherString) public boolean startsWith(String prefix) public boolean endsWith(String suffix) public indexOf(char ch) public indexOf(char ch, int start) public indexOf(String str) public indexOf(String str,int start) public lastIndexOf(char ch) public lastIndexOf(char ch,int start) public lastIndexOf(String str) public lastIndexOf(String str,int start)

6 String 常用方法(二) public String substring(int beginIndex)
public String substring(int beginIndex, int endIndex) public String concat(String str) public String replace(char oldChar,char newChar) public String toLowerCase( ) public String toUpperCase( ) public char[ ] toCharArray( ) public static String valueOf(long l)

7 StringBuffer 的常用方法 public StringBuffer append(String str)
public StringBuffer insert(int offset,String str) public StringBuffer delete(int start,int end) public StringBuffer deleteCharAt(int index) public StringBuffer replace(int start,int end,String str) public void setCharAt(int index,char ch) public StringBuffer reverse( ) public int length( ) public int capacity( ) public void setLength(int newLength)


Download ppt "第九章 字符串."

Similar presentations


Ads by Google