国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - java list與數(shù)組之間的轉(zhuǎn)換詳細(xì)解析

java list與數(shù)組之間的轉(zhuǎn)換詳細(xì)解析

2019-10-12 11:53java之家 Java教程

以下是對(duì)java中l(wèi)ist與數(shù)組之間的轉(zhuǎn)換進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下

1 數(shù)組轉(zhuǎn)換為L(zhǎng)ist
調(diào)用Arrays類(lèi)的靜態(tài)方法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中提供了一種使用的方法。更為常用的示例代碼:

復(fù)制代碼代碼如下:

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


2 List轉(zhuǎn)換為數(shù)組
這里的List以ArrayList為例,ArrayList的API提供了兩種可供使用的函數(shù)。

 

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

用法:示例代碼:

復(fù)制代碼代碼如下:

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩成人在线一区二区 | 亚州av影院 | h小视频在线 | 可以看av的网站 | 日韩电影在线 | 成人免费在线 | 欧美国产伦久久久久久 | 欧美午夜精品久久久久久浪潮 | 爱色区综合网 | 日本在线视频一区二区 | 精品国产91乱码一区二区三区 | 免费一级性片 | 国产欧美精品一区二区 | 亚洲精品免费看 | 欧美国产日韩一区二区三区 | 欧洲亚洲视频 | 日韩小视频网站 | 一级a毛片 | 精品无码久久久久久久动漫 | 欧美黄色片免费观看 | 久久国产欧美日韩精品 | 成人午夜精品久久久久久久3d | 午夜精品福利在线观看 | 久久精品一区二区 | 国产目拍亚洲精品99久久精品 | 岛国一区 | 一级毛片视频 | 国外爱爱视频 | 在线中文字幕视频 | 国产目拍亚洲精品99久久精品 | 日本一区二区三区精品视频 | 九九在线视频 | 欧美一二三 | 国产一区二区三区播放 | 福利视频在线 | 精品国产一区二区三区日日嗨 | 亚洲一本| 亚洲视频自拍 | 日本在线视频免费观看 | 成人片在线播放 | 久久国产高清 |