Java Collections - Maps and Sets: put cannot be applied -
i'm having trouble code. trying create student database. need create set of students represented course name. course name mapped set of students. i've tried write 'add' method when try .put database error message: put(java.lang.string,java.util.set) in java.util.map> cannot applied (java.lang.integer,studentdatabase.student). appreciated!!!!
import java.util.*;
public class studentdatabase {
private map<string, set<integer>> database = new treemap<string, set<integer>>(); private static class student extends treeset<integer> { public int id; public student(int id){ this.id = id; } } public void add(string coursename, integer student) { /* i've tried use way add database , doesn't work too. set<integer> studentset = database.get(coursename); if (studentset == null){ studentset = new treeset<integer>(); } studentset.add(student); database.put(coursename, student); */ integer idint = new integer(idint); if (database.containskey(idint)){ //if student duplicate, ok } else{ student info = new student(idint); database.put(new integer(idint), info); } } // end add
}
the answer right in error message: put(java.lang.string,java.util.set) in java.util.map> cannot applied (java.lang.integer,studentdatabase.student)
. type in second list doesn't match type in first list?
Comments
Post a Comment