欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
string類(lèi)的使用方法
String:字符串類(lèi)型

1、構造函數。

    String() :構造一個(gè)空字符串對象。
    String(byte[] bytes) :通過(guò)byte數組構造字符串對象。
    String(byte[] bytes, int offset, int length) :通過(guò)byte數組,從offset開(kāi)始,總共length長(cháng)的字節構造字符串對象。
    String(char[] value) :通過(guò)char數組構造字符串對象。
    String(char[] value, int offset, int count) :通過(guò)char數組,從offset開(kāi)始,總共length長(cháng)的字節構造字符串對象。
    String(String original) :構造一個(gè)original的副本。既,拷貝一個(gè)original。
    String(StringBuffer buffer) :通過(guò)StringBuffer數組構造字符串對象;

	byte[] b = {‘a(chǎn)‘,‘b‘,‘c‘,‘d‘,‘e‘,‘f‘,‘g‘,‘h‘,‘i‘,‘j‘};
char[] c = {‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘};

String sb = new String(b);
String sb_sub = new String(b,3,2);
String sc = new String(c);
String sc_sub = new String(c,3,2);
String sb_copy = new String(sb);

System.out.println("sb: " + sb );
System.out.println("sb_sub: " + sb_sub );
System.out.println("sc: " + sc );
System.out.println("sc_sub: " + sc_sub );
System.out.println("sb_copy: " + sb_copy );
結果為:
sb: abcdefghij
sb_sub: de
sc: 0123456789
sc_sub: 34
sb_copy: abcdefghij

2、方法。
說(shuō)明:
1. 所有方法均為public;
2. 書(shū)寫(xiě)格式:[修飾符] <返回類(lèi)型> <方法名([參數列表])>

如:
static int parseInt(String s) 表示:此方法(parseInt)為類(lèi)方法(static),返回類(lèi)型為(int),方法所需參數為String類(lèi)型。



    1. char charAt(int index) :取字符串中的某一個(gè)字符,其中的參數index指的是字符串中序數。字符串的序數從0開(kāi)始到length()-1 。

	String s = new String("abcdefghijklmnopqrstuvwxyz");
System.out.println("s.charAt(5): " + s.charAt(5) );
結果為:s.charAt(5): f

    2. int compareTo(String anotherString) :當前String對象與anotherString比較。相等關(guān)系返回0;不相等時(shí),從兩個(gè)字符串第0個(gè)字符開(kāi)始比較,返回第一個(gè)不相等的字符差,另一種情況,較長(cháng)字符串的前面部分恰巧是較短的字符串,返回它們的長(cháng)度差。
    3. int compareTo(Object o) :如果o是String對象,和2的功能一樣;否則拋出ClassCastException異常。

	String s1 = new String("abcdefghijklmn");
String s2 = new String("abcdefghij");
String s3 = new String("abcdefghijalmn");

System.out.println("s1.compareTo(s2): " + s1.compareTo(s2) );//返回長(cháng)度差
System.out.println("s1.compareTo(s3): " + s1.compareTo(s3) );//返回‘k‘-‘a(chǎn)‘的差
結果為:
s1.compareTo(s2): 4
s1.compareTo(s3): 10


    4. String concat(String str) :將該String對象與str連接在一起。
    5. boolean contentEquals(StringBuffer sb) :將該String對象與StringBuffer對象sb進(jìn)行比較。
    6. static String copyValueOf(char[] data)
    7. static String copyValueOf(char[] data, int offset, int count) :這兩個(gè)方法將char數組轉換成String,與其中一個(gè)構造函數類(lèi)似。
    8. boolean endsWith(String suffix) :該String對象是否以suffix結尾。

	String s1 = new String("abcdefghij");
String s2 = new String("ghij");
System.out.println("s1.endsWith(s2): " + s1.endsWith(s2) );
結果為:s1.endsWith(s2): true


    9. boolean equals(Object anObject) :當anObject不為空并且與當前String對象一樣,返回true;否則,返回false。
    10. byte[] getBytes() :將該String對象轉換成byte數組。
    11. void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) :該方法將字符串拷貝到字符數組中。其中,srcBegin為拷貝的起始位置、srcEnd為拷貝的結束位置、字符串數值dst為目標字符數組、dstBegin為目標字符數組的拷貝起始位置。

	char[] s1 = {‘I‘,‘ ‘,‘l‘,‘o‘,‘v‘,‘e‘,‘ ‘,‘h‘,‘e‘,‘r‘,‘!‘};//s1=I love her!
String s2 = new String("you!");
s2.getChars(0,3,s1,7); //s1=I love you!
System.out.println( s1 );
結果為:I love you!

    12. int hashCode() :返回當前字符的哈希表碼。
    13. int indexOf(int ch) :只找第一個(gè)匹配字符位置。
    14. int indexOf(int ch, int fromIndex) :從fromIndex開(kāi)始找第一個(gè)匹配字符位置。
    15. int indexOf(String str) :只找第一個(gè)匹配字符串位置。
    16. int indexOf(String str, int fromIndex) :從fromIndex開(kāi)始找第一個(gè)匹配字符串位置。

	String s = new String("write once, run anywhere!");
String ss = new String("run");
System.out.println("s.indexOf(‘r‘): " + s.indexOf(‘r‘) );
System.out.println("s.indexOf(‘r‘,2): " + s.indexOf(‘r‘,2) );
System.out.println("s.indexOf(ss): " + s.indexOf(ss) );
結果為:
s.indexOf(‘r‘): 1
s.indexOf(‘r‘,2): 12
s.indexOf(ss): 12

    17. int lastIndexOf(int ch)
    18. int lastIndexOf(int ch, int fromIndex)
    19. int lastIndexOf(String str)
    20. int lastIndexOf(String str, int fromIndex) 以上四個(gè)方法與13、14、15、16類(lèi)似,不同的是:找最后一個(gè)匹配的內容。
    21. int length() :返回當前字符串長(cháng)度。
    22. String replace(char oldChar, char newChar) :將字符號串中第一個(gè)oldChar替換成newChar。
    23. boolean startsWith(String prefix) :該String對象是否以prefix開(kāi)始。
    24. boolean startsWith(String prefix, int toffset) :該String對象從toffset位置算起,是否以prefix開(kāi)始。

	String s = new String("write once, run anywhere!");
String ss = new String("write");
String sss = new String("once");
System.out.println("s.startsWith(ss): " + s.startsWith(ss) );
System.out.println("s.startsWith(sss,6): " + s.startsWith(sss,6) );
結果為:
s.startsWith(ss): true
s.startsWith(sss,6): true

    25. String substring(int beginIndex) :取從beginIndex位置開(kāi)始到結束的子字符串。
    26.String substring(int beginIndex, int endIndex) :取從beginIndex位置開(kāi)始到endIndex位置的子字符串。
    27. char[] toCharArray() :將該String對象轉換成char數組。
    28. String toLowerCase() :將字符串轉換成小寫(xiě)。
    29. String toUpperCase() :將字符串轉換成大寫(xiě)。

	String s = new String("java.lang.Class String");
System.out.println("s.toUpperCase(): " + s.toUpperCase() );
System.out.println("s.toLowerCase(): " + s.toLowerCase() );
結果為:
s.toUpperCase(): JAVA.LANG.CLASS STRING
s.toLowerCase(): java.lang.class string

    30. static String valueOf(boolean b)
    31. static String valueOf(char c)
    32. static String valueOf(char[] data)
    33. static String valueOf(char[] data, int offset, int count)
    34. static String valueOf(double d)
    35. static String valueOf(float f)
    36. static String valueOf(int i)
    37. static String valueOf(long l)
    38. static String valueOf(Object obj)
    以上方法用于將各種不同類(lèi)型轉換成Java字符型。這些都是類(lèi)方法。

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Java中String類(lèi)的方法及說(shuō)明
一個(gè)通用的字符串檢測方法
【Java字符串】字符串雖簡(jiǎn)單,但這些你不一定知道【小白一定要注意】
Java中類(lèi)型的轉化
java筆試題大匯總(三)
JAVA String類(lèi)經(jīng)常用方法
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久