全屏
java.util.LinkedList.toArray ) )方法从头到尾返回包含此列表中正确序列中所有元素的数组。 此方法在基于数组的API和集合的API之间建立桥梁。
发表声明
以下是java.util.LinkedList.toArray ()方法的声明publicObject[]toArray ) ) )。
参数NA
返回值
此方法返回以正确顺序包含此列表中所有元素的数组
异常NA
范例
此示例说明如何使用java.util.LinkedList.toArray ()方法: packagecn.sxt;
importjava.util.*;
publicclassLinkedListDemo{
publicstaticvoidmain (字符串[ ] args ) {
//createaLinkedList
链接列表列表=new linked list (;
//addsomeelements
list.add(Hello );
list.add(2;
list.add(chocolate );
list.add('10 );
//打印the list
system.out.println (链接列表: )列表;
//createanarrayandcopythelisttoit
Object[]array=list.toArray (;
//打印队列
for(inti=0; I
system.out.println(Array: ) Array[I];
}
}
}
试着编译并运行上面的程序。 这将产生以下结果: 链接列表: [ hello,2,Chocolate,10]
Array:Hello
Array:2
Array:Chocolate
Array:10
共享到:
0评论