<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      java常用類的使用方法

      java常用類的使用方法


      Interger:整數類型

      1、屬性。


      static int MAX_VALUE:返回最大的整型數;
      static int MIN_VALUE:返回最小的整型數;
      static Class TYPE :返回當前類型。

      例子:
      代碼:
      System.out.println("Integer.MAX_VALUE: " + Integer.MAX_VALUE );
      結果為:Integer.MAX_VALUE: 2147483647
       


      2、構造函數。


      Integer(int value) :通過一個int的類型構造對象;
      Integer(String s) :通過一個String的類型構造對象;

      例子:
      代碼:
      Integer i = new Integer("1234");
      生成了一個值為1234的Integer對象。
       


      3、方法。
      說明:
      1. 所有方法均為public;
      2. 書寫格式:〔修飾符〕 <返回類型> <方法名(〔參數列表〕)>
      如:
      static int parseInt(String s) 表示:此方法(parseInt)為類方法(static),返回類型為(int),方法所需參數為String類型。

       

      1. byteValue():取得用byte類型表示的整數;
      2. int compareTo(Integer anotherInteger) :比較兩個整數。相等時返回0;小于時返回負數;大于時返回正數。

      例子:
      代碼:

      Integer i = new Integer(1234);
      System.out.println("i.compareTo: " + i.compareTo(new Integer(123)) );
      結果為:i.compareTo: 1
       

       

      3. int compareTo(Object o) :將該整數與其他類進行比較。如果o也為Integer類,進行方法2 的操作;否則,拋出ClassCastException異常。
      4. static Integer decode(String nm) :將字符串轉換為整數。
      5. double doubleValue() :取得該整數的雙精度表示。
      6. boolean equals(Object obj) :比較兩個對象。
      7. float floatValue() :取得該整數的浮點數表示。
      8. static Integer getInteger(String nm) :根據指定名確定系統特征值。
      9. static Integer getInteger(String nm, int val) :上面的重載。
      10. static Integer getInteger(String nm, Integer val) :上面的重載。
      11. int hashCode() :返回該整數類型的哈希表碼。
      12. int intValue() : 返回該整型數所表示的整數。
      13. long longValue() :返回該整型數所表示的長整數。
      14. static int parseInt(String s) :將字符串轉換成整數。s必須是時進制數組成,否則拋出NumberFormatException異常。
      15. static int parseInt(String s, int radix) :以radix為基數radix返回s的十進制數。所謂的基數,就是“幾進制”。

      例子:
      代碼:

      String s1 = new String("1010");
      System.out.println("Integer.parseInt(String s, int radix): " + Integer.parseInt(s1,2) );
      結果為:Integer.parseInt(String s, int radix): 10
       

       

      16. short shortValue() :返回該整型數所表示的短整數。
      17. static String toBinaryString(int i) :將整數轉為二進制數的字符串。
      18. static String toHexString(int i) :將整數轉為十六進制數的字符串。
      19. static String toOctalString(int i) :將整數轉為八進制數的字符串。
      20. String toString() :將該整數類型轉換為字符串。
      21. static String toString(int i) :將該整數類型轉換為字符串。不同的是,此為類方法。
      22. static String toString(int i, int radix) :將整數i以基數radix的形式轉換成字符串。

      例子:
      代碼:
      int i1 = 54321;
      System.out.println("Integer.toString(int i, int radix): " + Integer.toString(i1,16) );
      結果為:Integer.toString(int i, int radix): d431

       

      23. static Integer valueOf(String s) :將字符串轉換成整數類型。
      24. static Integer valueOf(String s, int radix) :將字符串以基數radix的要求轉換成整數類型。
       

      Float類的使用方法

      Float:實數類型

      1、屬性。


      1. static float MAX_VALUE : 返回最大浮點數,在不同硬件平臺中由Float.intBitsToFloat(0x7f7fffff)計算得出。
      2. static float MIN_VALUE : 返回最小浮點數,在不同硬件平臺中由Float.intBitsToFloat(0x1)計算得出。
      3. static float NaN : 表示非數值類型的浮點數,在不同硬件平臺中由Float.intBitsToFloat(0x7fc00000)計算得出。
      4. static float NEGATIVE_INFINITY:返回負無窮浮點數,在不同硬件平臺中由Float.intBitsToFloat(0xff800000)計算得出。
      5. static float POSITIVE_INFINITY :返回正無窮浮點數,在不同硬件平臺中由Float.intBitsToFloat(0x7f800000)計算得出。
      6. static Class TYPE :返回當前類型。


      2、構造函數。


      Float(double value) :以double類型為參數構造Float對象。
      Float(float value) :以Float類型為參數構造Float對象。
      Float(String s) :以String類型為參數構造Float對象。


      3、方法。
      說明:
      1. 所有方法均為public;
      2. 書寫格式:〔修飾符〕 <返回類型> <方法名(〔參數列表〕)>
      如:
      static int parseInt(String s) 表示:此方法(parseInt)為類方法(static),返回類型為(int),方法所需參數為String類型。

       

      1. byte byteValue() :返回以字節表示的浮點數。
      2. static int compare(float f1, float f2) :此為類方法,比較f1和f2。相當于new Float(f1).compareTo(new Float(f2))。如果f1與f2相等,返回0;小于關系,返回負數;大于關系,返回正數。
      3. int compareTo(Float anotherFloat) :此為對象方法,當前對象與anotherFloat比較。與2的比較規則相同。
      4. int compareTo(Object o) :當前對象與o進行比較,如果o屬于Float類,那么,相當于3;如果是其他類,則拋出ClassCastException異常。
      5. double doubleValue() :返回浮點數的雙精度值。
      6. boolean equals(Object obj) :比較當前Float對象與obj的內容是否相同。大多數情況是比較兩個Float對象的值是否相等,相當于f1.floatValue() == f2.floatValue()的值。與2、3、4不同的是:6返回boolean型。
      7. static int floatToIntBits(float value):按照IEEE 754轉化成float并輸出它的十進制數值。
      8. float floatValue() :返回該浮點數對象的浮點數值。
      9. int hashCode() :返回該Float對象的哈希表碼。
      10. int intValue() :返回該Float對象的整數值(整數部分)。
      11. boolean isInfinite() :判斷該Float對象是否是無窮。
      12. static boolean isInfinite(float v) :與11類似,不同的是:此為類方法,判斷的是v。
      13. boolean isNaN() :判斷該Float對象是否為非數值。
      14. static boolean isNaN(float v) :功能與13一樣,只不過判斷v。
      15. long longValue() :返回該Float對象的長整數值。
      16. static float parseFloat(String s) :將字符串轉換成浮點數。
      17. short shortValue() :返回該Float對象的短整數值。
      18. String toString() :將該Float對象轉換成字符串。
      19. static String toString(float f) :功能與18一樣,只是轉換f。
      20. static Float valueOf(String s) :將字符串轉換成浮點數。


      例子:
      代碼:
      Float f = new Float(1237.45);
      Float fs = new Float("123.45");
      Float fd = new Float(1234146865679824657987947924623724749.16416925);

      System.out.println("f.compare(fs): " + f.compareTo(fs) );
      System.out.println("f.compareTo(fd): " + f.compareTo(fd) );
      System.out.println("Float.compare(1.23f,3.25f): " + Float.compare(1.23f,3.25f) );
      結果為:
      f.compare(fs): 1
      f.compareTo(fd): -1
      Float.compare(1.23f,3.25f): -1


      代碼:
      Float f = new Float(1237.45);
      System.out.println("f.equals(fs): " + f.equals(fs) );
      結果為:f.equals(fs): false


      Double類的使用方法


      Double:雙精度類型

      1、屬性。

       

      1. static Double MAX_VALUE : 返回最大雙精度數,在不同硬件平臺中由Double.longBitsToDouble(0x7fefffffffffffffL)計算得出。
      2. static Double MIN_VALUE : 返回最小雙精度數,在不同硬件平臺中由Double.longBitsToDouble(0x1L)計算得出。
      3. static Double NaN : 表示非數值類型的雙精度數,在不同硬件平臺中由Double.longBitsToDouble(0x7ff8000000000000L)計算得出。
      4. static Double NEGATIVE_INFINITY:返回負無窮雙精度數,在不同硬件平臺中由Double.longBitsToDouble(0xfff0000000000000L)計算得出。
      5. static Double POSITIVE_INFINITY :返回正無窮雙精度數,在不同硬件平臺中由Double.longBitsToDouble(0x7ff0000000000000L)計算得出。
      6. static Class TYPE :返回當前類型。

      2、構造函數。


      Double(double value) :以double類型為參數創建Double對象。
      Double(String s) :以String類型為參數創建String對象。

      3、方法。
      說明:
      1. 所有方法均為public;
      2. 書寫格式:〔修飾符〕 <返回類型> <方法名(〔參數列表〕)>
      如:
      static int parseInt(String s) 表示:此方法(parseInt)為類方法(static),返回類型為(int),方法所需參數為String類型。

       

      1. byte byteValue() :返回以字節表示的雙精度數。
      2. static int compare(double d1, double d2) :此為類方法,比較d1和d2。相當于new Double(d1).compareTo(new Double(d2))。如果d1與d2相等,返回0;小于關系,返回負數;大于關系,返回正數。
      3. int compareTo(Double anotherDouble) :此為對象方法,當前對象與anotherDouble比較。與2的比較規則相同。
      4. int compareTo(Object o) :當前對象與o進行比較,如果o屬于Double類,那么,相當于3;如果是其他類,則拋出ClassCastException異常。
      5. static long doubleToLongBits(double value) :把value按照IEEE 754轉化成long并輸出它的十進制數值。
      6. double doubleValue() :返回該雙精度數對象的雙精度數值。
      7. boolean equals(Object obj) :比較當前Double對象與obj的內容是否相同。大多數情況是比較兩個Double對象的值是否相等,相當于d1.doubleValue() == d2.doubleValue()的值。
      8. float floatValue() :返回該浮點數對象的浮點數值。
      9. int hashCode() :返回該Double對象的哈希表碼。
      10. int intValue() :返回該Double對象的整數值(整數部分)。
      11. boolean isInfinite() :判斷該Double對象是否是無窮。
      12. static boolean isInfinite(double v) :與11類似,不同的是:此為類方法,判斷的是v。
      13. boolean isNaN() :判斷該Double對象是否為非數值。
      14. static boolean isNaN(double v) :功能與13一樣,只不過判斷v。
      15. long longValue() :返回該Double對象的長整數值。
      16. static float parseFloat(String s) :將字符串轉換成雙精度數。
      17. short shortValue() :返回該Double對象的短整數值。
      18. String toString() :將該Double對象轉換成字符串。
      19. static String toString(Double f) :功能與18一樣,只是轉換f。
      20. static Double valueOf(String s) :將字符串轉換成雙精度數。

      例子:與Float類的相似。

       

      Character類的使用方法


      Character:字符類型

      1、屬性。


      static int MIN_RADIX :返回最小基數。
      static int MAX_RADIX :返回最大基數。
      static char MAX_VALUE :字符類型的最大值。
      static char MIN_VALUE :字符類型的最小值。
      static Class TYPE :返回當前類型。

      2、構造函數。


      Character(char value):以char參數構造一個Character對象。

      3、方法。
      說明:
      1. 所有方法均為public;
      2. 書寫格式:〔修飾符〕 <返回類型> <方法名(〔參數列表〕)>
      如:
      static int parseInt(String s) 表示:此方法(parseInt)為類方法(static),返回類型為(int),方法所需參數為String類型。


      1. char charValue() :返回字符對象的值。
      2. int compareTo(Character anotherCharacter) :當前Character對象與anotherCharacter比較。相等關系返回0;小于關系返回負數;大于關系返回正數。
      3. int compareTo(Object o) :當前對象與另一個對象進行比較。如果o是Character對象,則與2功能一樣;否則,拋出ClassCastException異常。
      4. static int digit(char ch, int radix) :根據基數返回當前字符的值的十進制。如果不滿足Character.MIN_RADIX <= radix <= Character.MAX_RADIX,或者,ch不是radix基數中的有效值,返回"-1";如果ch是“大寫”的A到Z之間,則返回ch - 'A' + 10 的值;如果是“小寫”a到z之間,返回ch - 'a' + 10 的值。

      代碼:
      System.out.println("Character.MIN_RADIX: " + Character.MIN_RADIX );
      System.out.println("Character.MAX_RADIX: " + Character.MAX_RADIX );
      System.out.println("Character.digit('2',2): " + Character.digit('2',2) );
      System.out.println("Character.digit('7',10): " + Character.digit('7',10) );
      System.out.println("Character.digit('F',16): " + Character.digit('F',16) );
      結果為:
      Character.MIN_RADIX: 2
      Character.MAX_RADIX: 36
      Character.digit('2',2): -1
      Character.digit('7',10): 7
      Character.digit('F',16): 15


      5. boolean equals(Object obj) :與obj對象比較。當且僅當obj不為“null”并且和當前Character對象一致時返回“true”。
      6. static char forDigit(int digit, int radix) :根據特定基數判斷當前數值表示的字符。4的逆運算,非法數值時返回“'/u0000'”。

      代碼:
      System.out.println("Character.MIN_RADIX: " + Character.MIN_RADIX );
      System.out.println("Character.MAX_RADIX: " + Character.MAX_RADIX );
      System.out.println("Character.forDigit(2,2): " + Character.forDigit(2,2) );
      System.out.println("Character.forDigit(7,10): " + Character.forDigit(7,10) );
      System.out.println("Character.forDigit(15,16): " + Character.forDigit(15,16) );
      結果為:
      Character.MIN_RADIX: 2
      Character.MAX_RADIX: 36
      Character.forDigit(2,2):
      Character.forDigit(7,10): 7
      Character.forDigit(15,16): f
       

       

      7. static int getNumericValue(char ch) :返回字符ch的數值。
      8. static int getType(char ch) :返回字符所屬類型。具體有哪些種類請查看Java文檔資料。
      9. int hashCode() :返回當前字符的哈希表碼。
      10. static boolean isDefined(char ch) :判斷字符ch在Unicode字符集是否用明確定義。
      11. static boolean isDigit(char ch) :判斷字符ch是否為數字。
      12. static boolean isIdentifierIgnorable(char ch) :判斷字符ch是否為Unicode字符集中可忽略的字符。
      13. static boolean isISOControl(char ch) :判斷字符ch是否為ISO標準中的控制字符。
      14.static boolean isJavaIdentifierPart(char ch) :判斷字符ch是否為Java中的部分標識符。
      15. static boolean isJavaIdentifierStart(char ch) :判斷字符ch是否為Java中的第一個標識符。
      16. static boolean isLetter(char ch) :判斷字符ch是否為字母。
      17. static boolean isLetterOrDigit(char ch) :判斷字符ch是否為字母或數字。
      18. static boolean isLowerCase(char ch) :判斷字符ch是否為小寫字母。
      19. static boolean isMirrored(char c) :根據Unicode表判斷字符c是否存在與之方向相反的字符。例如:“〔”存在與之方向相反的“〕”,結果為:true。
      20. static boolean isSpaceChar(char ch) :判斷字符ch是否為Unicode中的空格。
      21. static boolean isUpperCase(char ch) :判斷字符ch是否為大寫字母。
      22. static boolean isWhitespace(char ch) :判斷字符ch是否為Java定義中的空字符。
      代碼:
      其中包括:
        char c1 = '/u0009';//水平列表符
        char c2 = '/u000A';//換行
        char c3 = '/u000B';//垂直列表符
        char c4 = '/u000C';//換頁
        char c5 = '/u000D';//回車
        char c6 = '/u001C';//文件分隔符
        char c7 = '/u001D';//組分隔符
        char c8 = '/u001E';//記錄分隔符
        char c9 = '/u001F';//單元分隔符

      23. static char toLowerCase(char ch) :轉換ch是否為小寫。
      24. String toString() :將當前Character對象轉換成字符串。
      25. static String toString(char c) :此為類方法,將c轉換成字符串。
      26. static char toUpperCase(char ch) :轉換ch是否為大寫。

      代碼:
      System.out.println("Character.toUpperCase('q'): " + Character.toUpperCase('q') );
      System.out.println("Character.toLowerCaseCase('B'): " + Character.toLowerCase('B') );
      結果為:
      Character.toUpperCase('q'): Q
      Character.toLowerCaseCase('B'): b

       

      string類的使用方法

      String:字符串類型
      此帖參考了maxlyy朋友的帖子,在這里特別感謝。
      1、構造函數。


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


      代碼:
        byte[] b = {'a','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、方法。
      說明:
      1. 所有方法均為public;
      2. 書寫格式:〔修飾符〕 <返回類型> <方法名(〔參數列表〕)>
      如:
      static int parseInt(String s) 表示:此方法(parseInt)為類方法(static),返回類型為(int),方法所需參數為String類型。

       

      1. char charAt(int index) :取字符串中的某一個字符,其中的參數index指的是字符串中序數。字符串的序數從0開始到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比較。相等關系返回0;不相等時,從兩個字符串第0個字符開始比較,返回第一個不相等的字符差,另一種情況,較長字符串的前面部分恰巧是較短的字符串,返回它們的長度差。
      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) );//返回長度差
        System.out.println("s1.compareTo(s3): " + s1.compareTo(s3) );//返回'k'-'a'的差
      結果為:
      s1.compareTo(s2): 4
      s1.compareTo(s3): 10

       

      4. String concat(String str) :將該String對象與str連接在一起。
      5. boolean contentEquals(StringBuffer sb) :將該String對象與StringBuffer對象sb進行比較。
      6. static String copyValueOf(char[] data) :
      7. static String copyValueOf(char[] data, int offset, int count) :這兩個方法將char數組轉換成String,與其中一個構造函數類似。
      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) :只找第一個匹配字符位置。
      14. int indexOf(int ch, int fromIndex) :從fromIndex開始找第一個匹配字符位置。
      15. int indexOf(String str) :只找第一個匹配字符串位置。
      16. int indexOf(String str, int fromIndex) :從fromIndex開始找第一個匹配字符串位置。

      代碼:
        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) 以上四個方法與13、14、15、16類似,不同的是:找最后一個匹配的內容。
      21. int length() :返回當前字符串長度。
      22. String replace(char oldChar, char newChar) :將字符號串中第一個oldChar替換成newChar。
      23. boolean startsWith(String prefix) :該String對象是否以prefix開始。
      24. boolean startsWith(String prefix, int toffset) :該String對象從toffset位置算起,是否以prefix開始。

      代碼:
        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位置開始到結束的子字符串。
      26.String substring(int beginIndex, int endIndex) :取從beginIndex位置開始到endIndex位置的子字符串。
      27. char[] toCharArray() :將該String對象轉換成char數組。
      28. String toLowerCase() :將字符串轉換成小寫。
      29. String toUpperCase() :將字符串轉換成大寫。

      代碼:
        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)
      以上方法用于將各種不同類型轉換成Java字符型。這些都是類方法。

       

      StringTokenizer類的使用方法

      StringTokenizer:字符串分隔解析類型
      屬于:java.util包。

      1、構造函數。


      1. StringTokenizer(String str) :構造一個用來解析str的StringTokenizer對象。java默認的分隔符是“空格”、“制表符(‘/t’)”、“換行符(‘/n’)”、“回車符(‘/r’)”。
      2. StringTokenizer(String str, String delim) :構造一個用來解析str的StringTokenizer對象,并提供一個指定的分隔符。
      3. StringTokenizer(String str, String delim, boolean returnDelims) :構造一個用來解析str的StringTokenizer對象,并提供一個指定的分隔符,同時,指定是否返回分隔符。


      2、方法。
      說明:
      1. 所有方法均為public;
      2. 書寫格式:〔修飾符〕 <返回類型> <方法名(〔參數列表〕)>
      如:
      static int parseInt(String s) 表示:此方法(parseInt)為類方法(static),返回類型為(int),方法所需參數為String類型。


      1. int countTokens() :返回nextToken方法被調用的次數。如果采用構造函數1和2,返回的就是分隔符數量(例2)。
      2. boolean hasMoreTokens() :返回是否還有分隔符。
      3. boolean hasMoreElements() :結果同2。
      4. String nextToken() :返回從當前位置到下一個分隔符的字符串。
      5. Object nextElement() :結果同4。
      6. String nextToken(String delim) :與4類似,以, 指定的分隔符返回結果。


      例子:
      代碼:
          String s = new String("The Java platform is the ideal platform for network computing");
          StringTokenizer st = new StringTokenizer(s);
          System.out.println( "Token Total: " + st.countTokens() );
          while( st.hasMoreElements() ){
            System.out.println( st.nextToken() );
                 }
      結果為:
      Token Total: 10
      The
      Java
      platform
      is
      the
      ideal
      platform
      for
      network
      computing
       

      例2:
      代碼:
          String s = new String("The=Java=platform=is=the=ideal=platform=for=network=computing");
          StringTokenizer st = new StringTokenizer(s,"=",true);
          System.out.println( "Token Total: " + st.countTokens() );
          while( st.hasMoreElements() ){
            System.out.println( st.nextToken() );
          }
      結果為:
      Token Total: 19
      The
      =
      Java
      =
      platform
      =
      is
      =
      the
      =
      ideal
      =
      platform
      =
      for
      =
      network
      =
      computing
       

      StringBuffer類的使用方法


      StringBuffer:StringBuffer類型

      描述:在實際應用中,經常回遇到對字符串進行動態修改。這時候,String類的功能受到限制,而StringBuffer類可以完成字符串的動態添加、插入和替換等操作。

      1、構造函數。

      StringBuffer() :構造一個沒有任何字符的StringBuffer類。
      StringBuffer(int length) : :構造一個沒有任何字符的StringBuffer類,并且,其長度為length。
      StringBuffer(String str) :以str為初始值構造一個StringBuffer類。


      2、方法。
      說明:
      1. 所有方法均為public;
      2. 書寫格式:〔修飾符〕 <返回類型> <方法名(〔參數列表〕)>
      如:
      static int parseInt(String s) 表示:此方法(parseInt)為類方法(static),返回類型為(int),方法所需參數為String類型。


      1. StringBuffer append(boolean b)
      2. StringBuffer append(char c)
      3. StringBuffer append(char[] str)
      4. StringBuffer append(char[] str, int offset, int len)
      5. StringBuffer append(double d)
      6. StringBuffer append(float f)
      7. StringBuffer append(int i)
      8. StringBuffer append(long l)
      9. StringBuffer append(Object obj)
      10. StringBuffer append(String str)
      11. StringBuffer append(StringBuffer sb)
      以上的方法都是向字符串緩沖區“追加”元素,但是,這個“元素”參數可以是布爾量、字符、字符數組、雙精度數、浮點數、整型數、長整型數對象類型的字符串、字符串和StringBuffer類等。如果添加的字符超出了字符串緩沖區的長度,Java將自動進行擴充。

      代碼:
          String question = new String("1+1=");
          int answer = 3;
          boolean result = (1+1==3);
         
          StringBuffer sb = new StringBuffer();
          sb.append(question);
          sb.append(answer);
          sb.append('/t');
          sb.append(result);
         
          System.out.println(sb);
      結果為:
      1+1=3  false


      12. int capacity() :返回當前StringBuffer對象(字符串緩沖區)的總空間,而非字符號串的長度。
      13. char charAt(int index) :在當前StringBuffer對象中取索引號為index的字符。第一個字符的索引為“0”
      14. StringBuffer delete(int start, int end) :刪除當前StringBuffer對象中以索引號start開始,到end結束的子串。
      15. StringBuffer deleteCharAt(int index) :刪除當前StringBuffer對象中索引號為index的字符。
      16. void ensureCapacity(int minimumCapacity) :重新設置字符號串緩沖區的總空間。如果minimumCapacity大于當前的總空間,則新的空間被設置:一種結果是minimumCapacity;另一種結果是{“老空間”乘2加2}。

      代碼:
          StringBuffer sb1 = new StringBuffer(5);
          StringBuffer sb2 = new StringBuffer(5);
         
          sb1.ensureCapacity(6);
          sb2.ensureCapacity(100);
         
          System.out.println( "sb1.Capacity: " + sb1.capacity() );
          System.out.println( "sb2.Capacity: " + sb2.capacity() );
      結果為:
      sb1.Capacity: 12
      sb2.Capacity: 100


      17. void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) :從當前StringBuffer對象的索引號srcBegin開始,到srcEnd結束的子串,賦值到字符數組dst中,并且從dst的索引號dstBegin開始。

      代碼:
          StringBuffer sb = new StringBuffer("I love her!");
          char[] i = {'I',' ','l','o','v','e',' ','y','o','u'};
         
          sb.getChars(7,10,i,7);
         
          System.out.println( "sb: " + sb );
      結果為:sb: I love her!


      18. int indexOf(String str) :返回當前StringBuffer對象中,第一個滿足str子串的位置。
      19. int indexOf(String str, int fromIndex) :從當前StringBuffer對象的fromIndex開始查找,返回第一個滿足str子串的位置。
      20. StringBuffer insert(int offset, boolean b)
      21. StringBuffer insert(int offset, char c)
      22. StringBuffer insert(int offset, char[] str)
      23. StringBuffer insert(int index, char[] str, int offset, int len)
      24. StringBuffer insert(int offset, double d)
      25. StringBuffer insert(int offset, float f)
      26. StringBuffer insert(int offset, int i)
      27. StringBuffer insert(int offset, long l)
      28. StringBuffer insert(int offset, Object obj)
      29. StringBuffer insert(int offset, String str)
      以上的方法都是在當前StringBuffer對象中插入一個元素,在索引號offset處插入相應的值。
      30. int lastIndexOf(String str) :返回當前StringBuffer對象中,最后一個滿足str子串的位置。
      31. int lastIndexOf(String str, int fromIndex) :從當前StringBuffer對象的fromIndex開始查找,返回最后一個滿足str子串的位置。
      32. int length() :返回當前StringBuffer對象(字符緩沖區)中,字符串的長度。注意:此方法與capacity() 不同。
      33. StringBuffer replace(int start, int end, String str) :替換當前StringBuffer對象的字符串。從start開始,到end結束的位置替換成str。
      34. StringBuffer reverse() :將字符串翻轉。

      代碼:
          StringBuffer sb = new StringBuffer("0123456789");
          System.out.println( "sb.reverse(): " + sb.reverse() );
      結果為:sb.reverse(): 9876543210


      35. void setCharAt(int index, char ch) :設置索引號index的字符為ch。
      36. void setLength(int newLength) :重新設置字符串緩沖區中字符串的長度,如果newLength小于當前的字符串長度,將截去多余的字符。

      代碼:
          StringBuffer sb = new StringBuffer("0123456789");
          sb.setLength(5);
          System.out.println( "sb: " + sb );
      結果為:sb: 01234


      37. String substring(int start) :取當前StringBuffer對象中,從start開始到結尾的子串。
      38. String substring(int start, int end) :取當前StringBuffer對象中,從start開始到end的子串。
      39. String toString() :將當前StringBuffer對象轉換成String對象。

       

      Random類的使用方法。


      屬于包:java.util.Random

      Random:隨機類型

      1、屬性。

      無。

      2、構造函數。

      Random() :創建一個新的隨機數發生器。

      Random(long seed) :用一個種子(長整型)創建一個隨機數發生器。

      3、方法。
      說明:
      1. 所有方法均為public;
      2. 書寫格式:〔修飾符〕 <返回類型> <方法名(〔參數列表〕)>
      如:
      static int parseInt(String s) 表示:此方法(parseInt)為類方法(static),返回類型為(int),方法所需參數為String類型。

       

      1. protected int next(int bits) :產生下一個偽隨機數。

      2. boolean nextBoolean() :返回下一個從隨機發生器的系列中得到的均勻分布的布爾值。

      3. void nextBytes(byte[] bytes) :產生隨機字節數組放到指定的數組中。

      4. double nextDouble() :返回下一個從隨機發生器的系列中得到的均勻分布的0.0到1.0的雙精度類型值。

      5. float nextFloat() :返回下一個從隨機發生器的系列中得到的均勻分布的0.0到1.0的浮點類型值。

      6. double nextGaussian() :返回下一個從隨機發生器的系列中得到的符合均勻分布的0.0的平均數到1.0方差的高斯分布雙精度類型值。

      7. int nextInt() :返回下一個從隨機發生器的系列中得到的均勻分布的整型值。

      8. int nextInt(int n) :返回下一個從隨機發生器的系列中得到的均勻分布的0到指定整型數(n)之間的整型值。

      9. long nextLong() :返回下一個從隨機發生器的系列中得到的均勻分布的長整型值。

      10. void setSeed(long seed) :設置隨機數發生器的種子為一個長整型數。


      關于種子的描述:
      這個類的對象使用一個48位的種子,
      如果這個類的兩個實例是用同一個種子創建的,
      并且,各自對它們以同樣的順序調用方法,
      則它們會產生相同的數字序列。

      下面就對上面的介紹做一個實驗,
      尤其注意相同種子時的結果,
      如果用默認的構造函數構造對象,
      他們是屬于同一個種子的。

      代碼:
      import java.util.Random;

      public class TestRandom{
        public static void main(String[] args){
          Random r1 = new Random(50);
          System.out.println("第一個種子為50的Random對象");
          System.out.println("r1.nextBoolean():/t" + r1.nextBoolean());
          System.out.println("r1.nextInt():/t/t" + r1.nextInt());
          System.out.println("r1.nextDouble():/t" + r1.nextDouble());
          System.out.println("r1.nextGaussian():/t" + r1.nextGaussian());
          System.out.println("---------------------------");
         
          Random r2 = new Random(50);
          System.out.println("第二個種子為50的Random對象");
          System.out.println("r2.nextBoolean():/t" + r2.nextBoolean());
          System.out.println("r2.nextInt():/t/t" + r2.nextInt());
          System.out.println("r2.nextDouble():/t" + r2.nextDouble());
          System.out.println("r2.nextGaussian():/t" + r2.nextGaussian());
          System.out.println("---------------------------");
         
          Random r3 = new Random(100);
          System.out.println("種子為100的Random對象");
          System.out.println("r3.nextBoolean():/t" + r3.nextBoolean());
          System.out.println("r3.nextInt():/t/t" + r3.nextInt());
          System.out.println("r3.nextDouble():/t" + r3.nextDouble());
          System.out.println("r3.nextGaussian():/t" + r3.nextGaussian());
         
          System.out.println("結果一目了然!");
        }
      }

      結果:
      代碼:

      第一個種子為50的Random對象
      r1.nextBoolean():    true
      r1.nextInt():       -1727040520
      r1.nextDouble():    0.6141579720626675
      r1.nextGaussian():   2.377650302287946
      ---------------------------
      第二個種子為50的Random對象
      r2.nextBoolean():    true
      r2.nextInt():       -1727040520
      r2.nextDouble():    0.6141579720626675
      r2.nextGaussian():   2.377650302287946
      ---------------------------
      種子為100的Random對象
      r3.nextBoolean():    true
      r3.nextInt():       -1139614796
      r3.nextDouble():    0.19497605734770518
      r3.nextGaussian():   0.6762208162903859
      結果一目了然!

      posted @ 2010-01-16 14:12  vipbooks  閱讀(227)  評論(0)    收藏  舉報
      主站蜘蛛池模板: gogogo高清在线播放免费| 亚洲色欲色欲www在线看| 国产成人无码A区在线观看视频| 日韩无套无码精品| 人妻夜夜爽天天爽| 国产一区二区不卡在线| 亚洲国产日韩a在线播放| 成年入口无限观看免费完整大片| 国产蜜臀精品一区二区三区| 日本阿v片在线播放免费| 国产精品福利一区二区三区| 成人无码午夜在线观看| 国内精品自线在拍| 国产精品美女一区二区三| av资源在线看免费观看| 亚洲国产精品va在线观看麻豆| 国产99视频精品免视看9| 精品人妻人人做人人爽夜夜爽| 亚洲区一区二区激情文学| 一卡2卡三卡4卡免费网站| 亚洲欧美高清在线精品一区二区| 欧美成人精品手机在线| 人妻无码av中文系列久| 高雄县| 狠狠躁夜夜人人爽天96| 亚洲欧美中文字幕日韩一区二区 | 亚洲中文字幕亚洲中文精| 国产精品人成视频免| 国产爆乳无码视频在线观看3| 久久精品娱乐亚洲领先| 日日躁夜夜躁狠狠躁超碰97| 亚洲第一精品一二三区| 好男人日本社区www| 91福利国产午夜亚洲精品| 麻豆国产成人AV在线播放| 少妇又爽又刺激视频| 精品人妻系列无码一区二区三区| 全免费A级毛片免费看无码| 人妻va精品va欧美va| 亚洲成在人天堂一区二区| 国产高清精品在线91|