定義方法 | 類型 | 描述 |
public String(char[] value) | 構造 | 直接將一個字符數組變為一個字符串 |
public String(char[] value,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) | 普通 | 從頭開始查找指定字符出串的位置 |
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 booleam starts With(String preifx) | 普通 | 判斷是否以指定的字符串開頭 |
public booleam endsWith(String guffix) | 普通 | 判斷是否以指定的字符串結尾 |
public booleam equals(String str) | 普通 | 判斷兩個字符串是否相等 |
1 public class six6{ 2 public static void main(String[] args){ 3 String str1="hello"; 4 char a[]=str1.toCharArray(); //將一個字符串轉換成字符數組。 5 for(int i=0;i<a.length;i++) 6 {System.out.print(a[i]+" ");} 7 System.out.println(""); 8 String str2=new String(a); //把a數組全部變為字符串 9 String str3=new String(a,1,3); //把a數組從第二個元素開始往后變為字符串 10 System.out.println(str2); //輸出字符串 11 System.out.println(str3); //輸出字符串 12 System.out.println(str1.charAt(4)); //取數第五個字符 13 System.out.println(str1.indexOf("ll")); //從頭開始查找指定字符串所在的位置,若沒有則返回-1 14 } 15 }
?