Collection 3
来源:互联网 发布:丽科cad软件下载 编辑:程序博客网 时间:2024/06/04 00:29
package niu.cheng1;
import java.util.ArrayList;
import java.util.Collection;
/*
* Collection 层次结构 中的根接口
*
* (集合的遍历)
* 把集合转换为数组
* Object[] toArray()返回包含此 collection 中所有元素的数组
* <T> T[] toArray(T[] a)返回包含此 collection 中所有元素的数组,返回数组的运行时类型与指定数组的运行时类型相同。
*/
public class CollectionDemo3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//创建集合1
Collection c1=new ArrayList();
c1.add("a1");
c1.add("ab2");
c1.add("abc3");
c1.add("abcd4");
//Object[] toArray()返回包含此 collection 中所有元素的数组
Object[] c=c1.toArray();
for(int x=0;x<c.length;x++){
//System.out.println(c[x]);
String s=(String)c[x];
System.out.println(s+"-------"+s.length());
}
}
}
import java.util.ArrayList;
import java.util.Collection;
/*
* Collection 层次结构 中的根接口
*
* (集合的遍历)
* 把集合转换为数组
* Object[] toArray()返回包含此 collection 中所有元素的数组
* <T> T[] toArray(T[] a)返回包含此 collection 中所有元素的数组,返回数组的运行时类型与指定数组的运行时类型相同。
*/
public class CollectionDemo3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//创建集合1
Collection c1=new ArrayList();
c1.add("a1");
c1.add("ab2");
c1.add("abc3");
c1.add("abcd4");
//Object[] toArray()返回包含此 collection 中所有元素的数组
Object[] c=c1.toArray();
for(int x=0;x<c.length;x++){
//System.out.println(c[x]);
String s=(String)c[x];
System.out.println(s+"-------"+s.length());
}
}
}
0 0
- Collection 3
- collection 3 List
- collection
- collection
- Collection
- collection
- collection
- collection
- Collection
- collection
- Collection
- Collection
- collection
- Collection
- Collection
- Collection
- Collection
- Collection
- 【天道酬勤】 腾讯、百度、网易游戏、华为Offer及笔经面经
- Collection 2
- 代码在线执行
- LT【深入Java虚拟机】之八:Java垃圾收集机制
- core data的学习
- Collection 3
- Java 代码安全(Coding Safe)
- 【LEETCODE】94-Binary Tree Inorder Traversal
- 记录c语言入门学习一
- Collection 4
- 51单片机控制直流电机
- Mac终端命令
- MySQL 种子重置指令
- 十分钟搞清字符集和字符编码