亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > Java > 正文

java list與數組之間的轉換詳細解析

2019-11-26 15:59:20
字體:
來源:轉載
供稿:網友

1 數組轉換為List
調用Arrays類的靜態方法asList。

asList
public static <T> List<T> asList(T... a)Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray(). The returned list is serializable and implements RandomAccess.
This method also provides a convenient way to create a fixed-size list initialized to contain several elements:

List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");

Parameters:
a - the array by which the list will be backed
Returns:
a list view of the specified array

用法:API中提供了一種使用的方法。更為常用的示例代碼:

復制代碼 代碼如下:

String[] arr = new String[] {"str1", "str2"};
List<String> list = Arrays.asList(arr);

2 List轉換為數組
這里的List以ArrayList為例,ArrayList的API提供了兩種可供使用的函數。

toArray
public Object[] toArray()Returns an array containing all of the elements in this list in proper sequence (from first to last element).
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>
Overrides:
toArray in class AbstractCollection<E>
Returns:
an array containing all of the elements in this list in proper sequence
See Also:
Arrays.asList(Object[])

--------------------------------------------------------------------------------
toArray
public <T> T[] toArray(T[] a)Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)

Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>
Overrides:
toArray in class AbstractCollection<E>
Parameters:
a - the array into which the elements of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the list
Throws:
ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this list
NullPointerException - if the specified array is null

用法:示例代碼:

復制代碼 代碼如下:

List<String> list = new ArrayList<String>();
list.add("str1");
list.add("str2");
int size = list.size();
String[] arr = (String[])list.toArray(new String[size]);//使用了第二種接口,返回值和參數均為結果

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美限制级电影在线观看| 国产乱肥老妇国产一区二| 日日狠狠久久偷偷四色综合免费| 久热精品视频在线观看一区| 中文字幕欧美在线| 亚洲视频日韩精品| 青青a在线精品免费观看| 国产日韩欧美成人| 国内自拍欧美激情| 国产主播喷水一区二区| 亚洲精品久久久久久下一站| 国产一区二区三区丝袜| 国产丝袜一区二区三区免费视频| 国产中文欧美精品| 国产欧美日韩综合精品| 日韩在线视频观看正片免费网站| 亚洲日本aⅴ片在线观看香蕉| 日本精品性网站在线观看| 国产精品视频永久免费播放| 日韩中文娱乐网| 亚洲欧美日韩爽爽影院| 日韩精品一区二区视频| 性色av一区二区三区红粉影视| 中文字幕欧美国内| 国产日韩欧美影视| 国产精品第七十二页| 亚洲人成电影在线观看天堂色| 精品视频在线播放色网色视频| 国产精品久久久久久av下载红粉| 日韩av电影国产| 欧美性xxxx极品高清hd直播| 亚洲精品自拍视频| 亚洲国产天堂久久国产91| 在线观看日韩av| xxxx欧美18另类的高清| 国内精品久久久| 91精品国产自产91精品| 欧美区二区三区| 亚洲色图第三页| 欧美日韩亚洲高清| 日韩国产欧美区| 91av在线网站| 国产精品一区二区女厕厕| 亚洲国产精品va在线观看黑人| 亚洲激情视频网| 中文字幕亚洲一区| 久久综合色影院| 久久人人爽人人爽人人片av高清| 亚洲第一页自拍| 538国产精品一区二区免费视频| 亚洲精品一区二三区不卡| 国产精品男女猛烈高潮激情| 日韩电影中文字幕在线| 欧美激情精品久久久久久久变态| 久久久久久亚洲| 欧美最猛性xxxxx亚洲精品| 国产福利视频一区| 亚洲男人天堂网站| 久久久久久12| 国产精品一二三视频| 国产精品成人久久久久| 久久久久久久激情视频| 成人免费淫片视频软件| 91精品国产777在线观看| 亚洲激情中文字幕| 国产女精品视频网站免费| 正在播放国产一区| 蜜臀久久99精品久久久久久宅男| 日韩成人在线网站| 狠狠色香婷婷久久亚洲精品| 亚洲欧美日韩网| 国产九九精品视频| 中文字幕欧美精品在线| 亚洲人精选亚洲人成在线| 国产精品久久久久久婷婷天堂| 亚洲欧美中文日韩在线v日本| 国产精品一区二区三区成人| 2025国产精品视频| 国产美女精品视频| 日韩欧美中文字幕在线观看| 美女啪啪无遮挡免费久久网站| 海角国产乱辈乱精品视频| 久久国产精品亚洲| 欧美黑人巨大xxx极品| 精品在线观看国产| 欧美影院成年免费版| 成人97在线观看视频| 国产91在线播放| 日韩免费av一区二区| 777国产偷窥盗摄精品视频| 久久综合88中文色鬼| 亚洲白拍色综合图区| 日韩精品在线免费播放| 亚洲精品天天看| 亚洲午夜久久久久久久| 亚洲欧洲日产国码av系列天堂| 亚洲黄色免费三级| 亚洲精品视频中文字幕| 欧美午夜精品久久久久久人妖| 国产精品视频99| 在线色欧美三级视频| 影音先锋欧美精品| 96精品视频在线| 国产精品一二三视频| 成人亲热视频网站| 一区二区三区久久精品| 91视频免费在线| 久久亚洲精品小早川怜子66| 九九热精品视频| 成人欧美一区二区三区黑人| 色一情一乱一区二区| 亚洲精品一二区| 国产视频久久久久久久| 国产成人一区三区| 91免费观看网站| 日本亚洲欧美成人| 日韩高清有码在线| 日韩欧美在线观看| 尤物99国产成人精品视频| 欧美一区二三区| 欧美又大粗又爽又黄大片视频| 亚洲福利在线视频| 欧美人在线观看| 欧美成人三级视频网站| 国产成人欧美在线观看| 欧美一级在线播放| 国产精品久久久久av| 成人欧美一区二区三区黑人孕妇| 欧美亚洲国产日韩2020| 久久精品电影一区二区| 国产精品丝袜久久久久久高清| 精品日本高清在线播放| 精品在线欧美视频| 欧美精品久久久久久久| 亚洲免费小视频| 久久久久久久久久久亚洲| 色偷偷91综合久久噜噜| 97久久精品国产| 日韩理论片久久| 17婷婷久久www| 91精品久久久久久久久久| 日韩成人中文电影| 91av在线国产| 视频在线观看一区二区| 国产欧美精品va在线观看| 69国产精品成人在线播放| 国产成人精品久久亚洲高清不卡| 91精品视频在线免费观看| 一区二区三区www| 日韩中文第一页| 日韩精品极品在线观看播放免费视频| 亚洲片av在线| 欧美国产在线电影| 国产视频亚洲视频| 欧美亚洲另类激情另类| 国产精品麻豆va在线播放| 欧美视频国产精品| 欧美高清自拍一区| 亚洲精品国产精品久久清纯直播| 在线色欧美三级视频| 91久久精品日日躁夜夜躁国产| 亚洲天堂av图片| 91在线免费观看网站| 成人黄色午夜影院|