【正文】
public static XXXX valueOf(String s)。 可以把這些類的對象所對應的值轉換成其它基本數據類型的值 類的介紹 /數據類型類 public String toString()。 public int intValue()。 靜態(tài)方法 ,無須創(chuàng)建 Integer對象 ,就可以方便地將字符串轉化成一個基本數據類型 int的量或者一個 Integer類的對象 類的介紹 /數據類型類 如 Double、 Float、 Byte、 Short、 Long等也都具有這些方法, public byte byteValue()。 將當前 Integer對象的 int量轉化成字符串 public static int parseInt(String s)。 public long longValue()。 public double doubleValue()。 例: Java的基本數據類型 ,如 int,double,char,long等。 public Object nextElement()——同 nextTokens()方法。 類的介紹 /StringTokenizer 常用方法: public boolean hasMoreTokens()——測試一個字符串分析器中是否有被分隔符隔開的子串可得到,如果有返回 true,否則返回 false。 類的介紹 /Random 成員方法: public void nextBytes(byte[] bytes) 生成隨即字節(jié)數據的字節(jié)數組 public int nextInt() 生成 int類型所表示的范圍中的隨機數 public int nextInt(int n) 生成 0n(不含 n)的隨機數 public long nextLont() 生成在 long類型所表示的范圍中的隨機數 public float nextFloat() 生成 (不含 )之間的隨機 float數 public double nextDouble() 生成 (不含 )之間的隨機 double數 例: 類的介紹 /StringTokenizer StringTokenizer類繼承自 Object類,用來為字符串構造一個分析器,該類在 。 } } Number of vector elements is 4 and they are: 5 Hi there! abcd 類的介紹 /Vector 類的介紹 /Random 該類繼承自 Object,在 。 (letters)。 (real)。 String s = new String (Hi there!)。d39。c39。b39。a39。 float real = 。 } } 類的介紹 /Vector public static void main (String args[]){ VectorDemo v = new VectorDemo()。 if (o instanceof char[]){ (((char[])o))。 i length。 (Number of vector elements is +length+ and they are:)。 } 類的介紹 /Vector public void printVector(){ Object o。 } public void addString(String s){ addElement(s)。 } public void addInt(int i){ addElement(new Integer(i))。 用 o置換 idx處的元素 類的介紹 /Vector import .*。 返回 Vector對象中元素的個數 boolean isEmpty()。 刪除第一個遇到的 o void removeElementAt(int index)。 在 idx處插入元素 o void removeAllElements()。 返回 index處的元素 類的介紹 /Vector int indexOf(Object o)。 返回第一個元素 (index = 0) Object lastElement()。 現(xiàn)版本 Java的 Vector類共有 42個方法 ,常用方法如下: void addElement(Object o)。 public Vector(int capacity, int increment)。 public Vector(Collection c)。 } } 為什么要有兩個字符串類 1. 如果創(chuàng)建一個字符串,不打算修改它,用 String 2. 如果創(chuàng)建一個字符串,計劃修改它,用 StringBuffer 3. String 比 StringBuffer 執(zhí)行效率高 4. StringBuffer 比 String 方便 類的介紹 /StringBuffer index, offset, 字符在字符串中的位置 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 T h i s a S t r i n g B u f f e r . substring(7,13) startindex = 7 offset = 8 endindex = 13 類的介紹 /StringBuffer 向量 (Vector)是 。 String s2 = (5, 11)。 */ public cla