Java中的字符串相關解讀

 Java字符串就是Unicode字符序列。Java沒有內置的字符串類型,而是在標準Java類庫中提供了一個預約義類String,位於java.lang包中,編譯器會默認導入這個包。字符串被做爲String類型的對象來處理。java

  建立String對象的方法:ide

  一、String s = "Hello World";code

  二、String s = new String();對象

  三、String s = new String("Hello World");索引

  獲取字符串的長度:字符串名。length();字符串

  字符串比較:字符串1.equals(字符串2);//相同的字母,大小寫不一樣也是不相同編譯器

  字符串1.equalsIgnoreCase(字符串2);//比較時忽略大小寫string

  toLowerCase()  轉換字符串中的英文字符爲小寫it

  toUpperCase()  轉換字符串中的英文字符爲大寫編譯

   字符串鏈接:

  一、使用"+"運算符,

  二、使用String類的concat()方法

  字符串經常使用的提取和查詢方法:

  方法 說明

  public  int  indexOf(int  ch) 搜索第一個出現的字符ch

  public  int  indexOf(String  value)  搜索第一個出現的字符串value

  public  int  lastIndexOf(int  ch) 搜索最後一個出現的字符ch

  public  int  lastIndexOf(String Value) 搜索最後一個出現的字符串value

  public  String  substring  (int  index) 提取從位置索引開始的字符串部分

  public  String  substring(int beginIndex,  int  endIndex); 提取beginIndex和endIndex之間的字符串部分

  public  String  trim(  ) 去除字符串的先後空格,並返回副本

相關文章
相關標籤/搜索