I have made a Student class and it in not getting initialized with LinkedHashMap. Giving compile time error :
The type LinkedHashMap is not generic;
it cannot be parameterized with arguments <Student, Integer>.
CODE :
StudentLinkedMap :
public class LinkedHashMap {
public static void main(String[] args) {
Map <Student,Integer> students = new LinkedHashMap<Student,Integer>();
Student s1 = new Student(1,2,"Dhwani","Pandya");
Student s2 = new Student(2,2,"Priyam ","Parekh");
Student s3 = new Student (3,2,"Sucheta","Shrivastava");
Student s4 = new Student(3,6,"Nirali","Rokadia");
Student s5 = new Student(2,6,"Kajari","Agrawal");
students.put(s1,2);
students.put(s2,4);
students.put(s3,6);
students.put(s4,5);
students.put(s5,7);
for(Map.Entry lhs:students.entrySet()){
System.out.println(lhs.getKey()+ " "+ lhs.getValue());
}
}
}
Student Class:
public class Student {
private int rollno;
private String firstname;
private String lastname;
private int std;
public Student(int rollno, int std,String firstname, String lastname){
this.firstname=firstname;
this.lastname=lastname;
this.rollno=rollno;
this.std=std;
}
@Override
public String toString(){
return ("\troll no="+ this.rollno + "\tstandard="+
this.std+"\tfirstname="+this.firstname+"\tlastname="+this.lastname);
}
}