关于Java的一个小程序有问题~~~
importjava.util.*;publicclassA{publicstaticvoidmain(String[]args){Collectionc=newHash...
import java.util.*;
public class A {
public static void main(String[] args) {
Collection c = new HashSet();
c.add(new Name("f1","l1"));
c.add(new Name("f2","l2"));
c.add(new Name("f3","l3"));
Iterator i = c.iterator();
while(i.hasNext()) {
Name a = (Name)i.next();
System.out.print(a.getFirstName() + " ");
}
}
}
class Name {
private String a,b;
Name(String i,String j) {
a = i;
b = j;
}
private String getFirstName() {
return this.a;
}
} 展开
public class A {
public static void main(String[] args) {
Collection c = new HashSet();
c.add(new Name("f1","l1"));
c.add(new Name("f2","l2"));
c.add(new Name("f3","l3"));
Iterator i = c.iterator();
while(i.hasNext()) {
Name a = (Name)i.next();
System.out.print(a.getFirstName() + " ");
}
}
}
class Name {
private String a,b;
Name(String i,String j) {
a = i;
b = j;
}
private String getFirstName() {
return this.a;
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询