import java.util.*;public class BasicContainer{
public static void main(String[] args){
Collection c = new HashSet();
c.add("hello");
c.add(new Name("f1","11"));
c.add(new Integer(100));
c.remove("hello");
c.remove(new Interger(100));
System.out.println(c.remove(new Name("f1","11")));
System.out.println(c);
}
} class Name{
private String firsName,lastName;
public Name(String firstName,String lastName){
this.firstName = firstName; this.lastName = lastName;
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String toString(){
return firstName + " " + lastName;
}
}问各大侠哪错了,咋改;
public static void main(String[] args){
Collection c = new HashSet();
c.add("hello");
c.add(new Name("f1","11"));
c.add(new Integer(100));
c.remove("hello");
c.remove(new Interger(100));
System.out.println(c.remove(new Name("f1","11")));
System.out.println(c);
}
} class Name{
private String firsName,lastName;
public Name(String firstName,String lastName){
this.firstName = firstName; this.lastName = lastName;
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String toString(){
return firstName + " " + lastName;
}
}问各大侠哪错了,咋改;
你这个程序一共2处错误import java.util.*;public class BasicContainer{
public static void main(String[] args){
Collection c = new HashSet();
c.add("hello");
c.add(new Name("f1","11"));
c.add(new Integer(100));
c.remove("hello");
c.remove(new Interger(100));//多打了一个r,自己看看
System.out.println(c.remove(new Name("f1","11")));
System.out.println(c);
}
}class Name{
private String firsName,lastName;//定义的时候少打了一个t
public Name(String firstName,String lastName){
this.firstName = firstName; this.lastName = lastName;
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String toString(){
return firstName + " " + lastName;
}
//最后的结果是
false
[f1 11]
这结果不知道是不是你想要的。
如果不是特别新手的话,而且经常打错代码的话,就弄一个编译环境用吧。省时间,不容易出错
import java.util.HashSet;public class BasicContainer {
public static void main(String[] args) {
Collection c = new HashSet();
c.add("hello");
c.add(new Name("f1", "11"));
c.add(new Integer(100));
c.remove("hello");
c.remove(new Integer(100));// 2、你的Integer都写错了
System.out.println(c.remove(new Name("f1", "11")));
System.out.println(c);
}
}class Name {
private String firstName, lastName; //3、 你的firstName 都写错了,
//接下来看看还有没有问题,再说··· public Name(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
} public String getFirstName() {
return firstName;
} public String getLastName() {
return lastName;
} public String toString() {
return firstName + " " + lastName;
}
}
LZ用的是eclipse么? 快捷键: “Shift + /”吧,不用什么都手工敲代码,效率低哈···
用的JCreator,改正后是这样的
import java.util.*;public class BasicContainer{
public static void main(String[] args){
Collection<Object> c = new HashSet<Object>();
c.add("hello");
c.add(new Name("f1","11"));
c.add(new Integer(100));
c.remove("hello");
c.remove(new Integer(100));//Ingeger
System.out.println(c.remove(new Name("f1","11")));
System.out.println(c);
}
}
class Name{
private String firstName,lastName;//firstName
public Name(String firstName,String lastName){
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String toString(){
return firstName + " " + lastName;
}
}