Iの値としてキーと学生オブジェクトとしてstudentIdsを保持するハッシュマップ、JavaでHashMapからオブジェクトを取得していますか?
HashMap<Integer, Student> hashMap = hashTables.buildHash(students);
public static HashMap<Integer, Student> buildHash(Student[] students) {
HashMap<Integer, Student> hashMap = new HashMap<Integer, Student>();
for (Student s : students) hashMap.put(s.getId(), s);
return hashMap;
}
以下のコードは、それぞれです。KeyValueペアとs.getValueを(取得を持っている)は、IDから構成されている学生のオブジェクトと文字列を返します名前、これらの値を取得/印刷する方法(student.int、student.name);
for(Map.Entry<Integer, Student> s : hashMap.entrySet())
System.out.print(s.getKey()+" "+s.getValue().getId()+" "+s.getValue().getName());
(つまり、言語のキーワードなので、クラスは「INT」という名前のフィールドを持つことは不可能だということに注意してください):
for(Map.Entry s : hashMap.entrySet())
System.out.print(s.getKey()+" "+s.getValue());
@Marko Topolnikことで、これをacheiveすることができます:私が使っていたという理由だけで彼のクラスの構造についてOPの構文違反の情報 –
もちろん、私はそれのユーモラスな側面を実現しました。それを模倣するよりも助けてほしいです:) HashMapの人口コードではゲッターを使っているので、おそらく 'id'と' name'はプライベートであるはずです。 –