JDK1.5特性实例

/**
* <p>description:JDK1.5特性实例:主要举出最常用的:Generic泛性、For-Each循环、Varargs变参数  </p>
* <p>Title:领头鸟咨询,带领您最先进入未来世界</p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: leaderbird</p>
* @author 李小强  leaderbird
* <p>author E-Mail: [email protected]
* <p>http://leaderbird.blogcn.com
* <p>@version 2.1</p>
* <p>@date : 2008-11-5
*/
class Temp{
String id ="";
public Temp() {
super();
}

public Temp(String id) {
super();
this.id = id;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
}

public class JdkTest {
// jdk1.5泛性、For-Each循环,特性实例
static List<String> processAll(List<Temp> c) {
List<String> strs = new ArrayList();
for (Temp emp : c) {
strs.add(emp.getId());
}
return strs;
}
//jdk1.5可变参数(Varargs),特性实例
public static void write(String... objs) {
for (String obj: objs){
System.out.print(obj);
}
System.out.print("\n");
}
public static void main(String args[]){
List<Temp> c = new ArrayList();
c.add(new Temp("1"));
c.add(new Temp("2"));
c.add(new Temp("3"));
List<String> strs =processAll(c);
for(String str: strs){
System.out.println(str);
}
write("hello");
write("hello"," world");
write("hello"," world"," welcome");
write("hello"," world"," welcome"," to");
write("hello"," world"," welcome"," to"," Leaderbird");
}
}

你可能感兴趣的:(C++,c,C#,咨询)