Guest User

123

a guest
Apr 25th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.TreeMap;
  3.  
  4. public class Mag {
  5. public TreeMap<Integer, ArrayList<String>> mas;
  6.  
  7. /* protected Mag(int n) {
  8. ArrayList<String> neo = new ArrayList<String>();
  9. for (int i = 1; i <= n; i++) {
  10. this.mas.put(i, neo);
  11. }
  12. } */
  13.  
  14. public void addNew(int k, String s) {
  15. ArrayList<String> neo = new ArrayList<String>();
  16. if (mas.containsKey(k)) {
  17. neo = mas.get(k);
  18. }
  19. neo.add(s);
  20. mas.put(k, neo);
  21.  
  22. }
  23.  
  24. protected void showDesk(int k) {
  25. ArrayList<String> neo = new ArrayList<String>();
  26. neo = mas.get(k);
  27. while (neo.iterator().hasNext()) {
  28. System.out.print(neo.iterator().next() + " ");
  29. System.out.println("");
  30. }
  31. }
  32. }
  33.  
  34.  
  35.  
  36. public class Main {
  37. public static void main(String[] args) {
  38. Mag mag = new Mag();
  39. mag.addNew(5,"SDF");
  40. mag.addNew(5,"SDuu");
  41. mag.addNew(5,"SDuygF");
  42. mag.showDesk(5);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment