码迷,mamicode.com
首页 > 编程语言 > 详细

java中String的21种用法

时间:2014-07-31 20:58:47      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:java   string   用法   

构造函数必须new出来

 * public String (char[] vaue)                         将一个字符数组变成字符串(构造函数)

 * public String (char[] vaue,int offset,int count)    将制定范围内的字符数组变为字符串(构造函数)

 * public String (byte[],bytes)                        将一个byte数组变为字符串(构造函数)

 * public String (byte[],bytes,int offset,int length)  将制定范围内的byte数组变为字符串(构造函数)

 * public char[] toCharArray()                         将一个字符串变为字符数组

 * public char charAt(int index)                       从一个字符串中取出顶顶位置的字符

 * public byte[](getBytes)                             将一个字符串变成byte数组

 * public int length()                                 取得字符串长度

 * public int indexOf(String str)                      从头开始查找指定字符串位置找不到返回-1

 * public int indexOf(String  str,int fromIndex)       从指定位置查找指定字符串位置

 * public String trim()                                清除左右两端的空格

 * public String substring(int beginIndex)             从指定位置开始一直取到尾进行字符串的提取

 * public String substring(int begin,int end)          指定截取字符串的开始点和结束点

 * public String[] split(String regex)                 按照指定的字符串对字符串进行拆分

 * public String toUpperCase()                         将一个字符串全部变为大写字母

 * public String toLowerCase()                         将一个字符串全部变为小写

 * public boolean startsWith(String prefix)            判断是否以字符串开头

 * public boolean endsWith(String suffix)              判断是否以字符串结尾

 * public boolean equals(String str)                   判断两个字符串是否相等

 * public boolean equalsIgnorCase(String str)           不区分大小写比较字符串是否相等

 * public String replaceAll(String regex,String replacement)字符串替换


  例:

public class StrDemos {
	public static void main(String args[]){
    char[] s={'g','1','c','c'};

    String str=null;
    str=new String(s);
    System.out.println(str);//将一个字符数组变成字符串
    
    
    char[]d=str.toCharArray();//将一个字符串转换为字符数组
    for(int i=0;i<d.length;i++){
    	System.out.println(d[i]);	
    }
    
	}
}
输出:
g1cc

g
1
c
c


java中String的21种用法,布布扣,bubuko.com

java中String的21种用法

标签:java   string   用法   

原文地址:http://blog.csdn.net/gao_chun/article/details/38321157

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!