首先,該方法是將數組轉化為list。有以下幾點需要注意:
(1)該方法不適用于基本數據類型(byte,short,int,long,float,double,boolean)
(2)該方法將數組與列表鏈接起來,當更新其中之一時,另一個自動更新
(3)不支持add和remove方法
上代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package com.hdu.test; import java.util.Arrays; import java.util.List; abstract public class AsllistTest { public static void main(String[] args) { String[] s = { "aa" , "bb" , "cc" }; List<String> strlist = Arrays.asList(s); for (String str:strlist){ System.out.println(str); } System.out.println( "------------------------" ); //基本數據類型結果打印為一個元素 int [] i ={ 11 , 22 , 33 }; List intlist = Arrays.asList(i); for (Object o:intlist){ System.out.println(o.toString()); } System.out.println( "------------------------" ); Integer[] ob = { 11 , 22 , 33 }; List<Integer> oblist = Arrays.asList(ob); for ( int a:oblist){ System.out.println(a); } System.out.println( "------------------------" ); } } |
運行結果:
1
2
3
4
5
6
7
8
|
aa bb cc ------------------------ [I@15db9742 ------------------------ 22 ------------------------ |
請參考這篇文章:http://m.ythuaji.com.cn/article/91152.html
以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持服務器之家!
原文鏈接:http://www.cnblogs.com/Miracle-Maker/p/6360069.html