fork download
  1. import java.util.*;
  2. import java.io.*;
  3. class Main{
  4. public static void main(String[] args) throws IOException{
  5. HashMap<String,Integer> map = new HashMap<String,Integer>();
  6.  
  7. /* データを読み込んで、mapにドンドン追加 */
  8. while(true){
  9. String name = br.readLine();
  10. int score = 0;
  11. /* nameがnullだったときは、equalsメソッドも使えないね */
  12. if(name == null){
  13. break;
  14. }
  15. score = Integer.parseInt(br.readLine());
  16. map.put(name,score);
  17. }
  18. ArrayList<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>();
  19. list.addAll((new HashMap<String,Integer>(map)).entrySet());
  20. list.get(0).setValue(2033);
  21. for(int i = 0;i < list.size();i++){
  22. System.out.println(list.get(i).getKey());
  23. System.out.println(list.get(i).getValue());
  24. }
  25. Iterator<String> ir = map.keySet().iterator();
  26. while(ir.hasNext()){
  27. String s = ir.next();
  28. System.out.println(s);
  29. System.out.println(map.get(s));
  30.  
  31. }
  32. }
  33. }
Success #stdin #stdout 0.04s 213440KB
stdin
相沢
37
石田
48
臼井
57
遠藤
36
小川
82
加藤
55
木島
37
工藤
25
stdout
小川
2033
石田
48
臼井
57
木島
37
相沢
37
工藤
25
加藤
55
遠藤
36
小川
82
臼井
57
石田
48
木島
37
工藤
25
相沢
37
加藤
55
遠藤
36