A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© yp324 中级黑马   /  2013-6-5 12:04  /  1611 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1.String 类代表字符串。字符串是常量,它们的值在创建之后不能更改。
一、构造方法摘要
二、方法摘要
1.增加
2.删除
3.修改
4.查找
5.替换
6.连接
7.比较
8.提取
9.转换
9-1.大小写
9-2.字符和编码
9-3.From其它类型
9-4.To其它类型
9-5.其它格式
10.Object本身相关
一、构造方法摘要
(一)空构造
String() //空字符序列。

(二)数组构造
1.字节
String(byte[] bytes) //byte数组(默认字符集解码)。
String(byte[] bytes, Charset charset) //byte数组,字符集对象(解码)。
String(byte[] bytes, String charsetName) //byte数组, 字符集名称(解码)。
String(byte[] bytes, int offset, int length) //byte子数组<起始位,长度>。
String(byte[] bytes, int offset, int length, Charset charset)
//byte子数组<起始位,长度>,字符集对象(解码)。
String(byte[] bytes, int offset, int length, String charsetName)
//byte子数组<起始位,长度>,指定字符集名称(解码)。
2.字符
String(char[] value) //char数组。
String(char[] value, int offset, int count) //char子数组<起始位,长度>。
3.整型
String(int[] codePoints, int offset, int count)
//int子数组<起始位,长度>,元素为Unicode代码点。(即字符编码为元素)
(三)对象构造
String(String original) //String构造String。(字符串的副本)
String(StringBuffer buffer) //使用StringBuffer构造。
String(StringBuilder builder) //使用StringBuilder构造。
         
归纳:使用 字符序列 形式构造。有字节byte[]、字符char[]和字符编码int[]三种数组,及String、StringBuffer和StringBuilder对象。
         
二、方法摘要
1.增加
2.删除
3.修改
4.查找
char charAt(int index) //返回指定索引处的 char 值。
int indexOf(int ch) //字符在串中第一次出现处的索引。无则返回 -1。
int indexOf(int ch, int fromIndex)
  //字符在串中第一次出现处的索引。无则返回 -1。
  //从指定的索引位置开始搜索。
int indexOf(String str)
  //子串在此串中第一次出现处的索引。无则返回 -1。
int indexOf(String str, int fromIndex)
  //子串在此串中第一次出现处的索引。无则返回 -1。从指定的索引位置开始搜索。
int lastIndexOf(int ch)
  //字符在此串中最后一次出现处的索引。无则返回 -1。
  //从最后一个字符开始反向搜索此 String。
int lastIndexOf(int ch, int fromIndex)
  //字符在此串中最后一次出现处的索引。无则返回 -1。
  //从指定的索引处开始进行反向搜索。
int lastIndexOf(String str)
  //子串在此串中最后一次出现处的索引。无则返回 -1。
int lastIndexOf(String str, int fromIndex)
  //子串在此串中最后一次出现处的索引。无则返回 -1。
  //从指定的索引处开始进行反向搜索。
5.替换
  String replace(char oldChar, char newChar)
//用 newChar 替换此字符串中出现的所有 oldChar,返回新串。 (左值替换)
//如果 oldChar 没有出现,则返回String本身。
 String replace(CharSequence target, CharSequence replacement)
//使用指定的字面值替换序列替换此字符串所有匹配字面值目标序列的子字符串。
//CharSequence接口的子类:String, StringBuffer, StringBuilder 等。(左值替换)
6.连接
String concat(String str) //将指定字符串连接到此字符串的结尾。

7.比较
int compareTo(String anotherString)
  //按字典顺序比较两个字符串中各字符的 Unicode 值。
  //返回;<0;==0 (equals(Object) 返回 true 时);>0;
  //在某个索引处的字符不同:this.charAt(k)-anotherString.charAt(k)
  //没有字符不同,长度不同:this.length()-anotherString.length()
    int compareToIgnoreCase(String str)
  //按字典顺序比较两个字符串,不考虑大小写。
boolean contains(CharSequence s)
  //当且仅当此字符串包含指定的 char 值序列时,返回 true。
  //CharSequence接口的子类:String, StringBuffer, StringBuilder 等。
  boolean contentEquals(CharSequence cs)
  //将此字符串与指定的 CharSequence 比较。
  //当表示相同的 char 值序列时,结果才为 true。  
  //CharSequence接口的子类:String, StringBuffer, StringBuilder 等。
boolean startsWith(String prefix)
  //测试此字符串是否以指定的前缀开始。
  //如果参数是空字符串"",或者等于此String对象(equals相等),则结果为true。
boolean startsWith(String prefix, int toffset)
  //测试此字符串从指定索引开始的子字符串是否以指定前缀开始。
boolean endsWith(String suffix)
   //测试此字符串是否以指定的后缀结束。
   //如果参数是空字符串"",或者等于此String对象(equals相等),则结果为true。
boolean equals(Object anObject) //将此字符串与指定的对象比较。
boolean equalsIgnoreCase(String anotherString)
  //将此 String 与另一个 String 比较,不考虑大小写。
boolean isEmpty() //当且仅当 length() 为 0 时返回 true。
boolean regionMatches(int toffset, String other, int ooffset, int len)
  //两个字符串的子串区域是否相等。
  //将此 String 对象的子字符串与参数 other 的子字符串进行比较。
  //toffset - 此字符串中子区域的起始偏移量。
  //other - 字符串参数。toffset - 字符串参数中子区域的起始偏移量。
  //len - 要比较的字符数。返回:相等,则返回 true;否则返回 false。
boolean regionMatches(boolean ignoreCase, int toffset,
      String other, int ooffset, int len)
  //两个字符串的子串区域是否相等。
  //ignoreCase - 如果为 true,则比较字符时忽略大小写。
  
8.提取
    String substring(int beginIndex)
  //返回子串,从指定索引处的字符开始,直到此字符串末尾。[起始位]
String substring(int beginIndex, int endIndex)
  //返回子串。[起始位,截止位)
String trim()   //返回字符串的副本,忽略前导空白和尾部空白。
9.转换
9-1.大小写
     String toLowerCase()
    //将 String 中的所有字符都转换为小写。(默认语言环境)
    //等效于调用 toLowerCase(Locale.getDefault())。
  String toUpperCase()
    //将 String 中的所有字符都转换为大写。(默认语言环境)
    //等效于调用 toUpperCase(Locale.getDefault())。
9-2.字符和编码
   int codePointAt(int index) //返回指定索引处的代码点(字符编码)。
9-3.From其它类型
   static String copyValueOf(char[] data)
    //复制char数组中的字符创建String。
   static String copyValueOf(char[] data, int offset, int count)
    //复制char子数组中的字符创建String。 char子数组<起始位,长度>
   static String valueOf(boolean b)
    //返回 boolean 参数的字符串表示形式。
   static String valueOf(char c)
    //返回 char 参数的字符串表示形式。
static String valueOf(char[] data)
//返回 char 数组参数的字符串表示形式。
static String valueOf(char[] data, int offset, int count)
//返回 char 数组参数的特定子数组的字符串表示形式。char子数组<起始位,长度>。
   static String valueOf(double d)
    //返回 double 参数的字符串表示形式。
   static String valueOf(float f)
    //返回 float 参数的字符串表示形式。
   static String valueOf(int i)
    //返回 int 参数的字符串表示形式。
   static String valueOf(long l)
    //返回 long 参数的字符串表示形式。
   static String valueOf(Object obj)
    //返回 Object 参数的字符串表示形式。
   
9-4.To其它类型
  byte[] getBytes() //编码为byte数组,默认字符集。
  byte[] getBytes(Charset charset)//编码为byte数组,使用给定字符集对象。
  byte[] getBytes(String charsetName)//编码为byte数组,使用给定字符集名称。
  void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
   //将字符从此字符串复制到目标字符数组。
   // [srcBegin,srcEnd) ===copy to===> char[dstBegin]
   
  char[] toCharArray() //将此字符串转换为一个新的字符数组。
9-5.其它格式
   static String format(String format, Object... args)
    //使用指定的格式字符串和参数返回一个格式化字符串。
    //参考链接:格式字符串语法
   
10.Object本身相关
  int hashCode() //返回此字符串的哈希码。
  int length() //返回此字符串的长度。即字符串中Unicode字符的数量。

评分

参与人数 1技术分 +1 收起 理由
袁梦希 + 1 淡定

查看全部评分

2 个回复

倒序浏览
总结帖,可以优化下,哪些觉得重要,是精华。不用说这么多,在博客里详细点
回复 使用道具 举报
涨姿势了。。。。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马