Advertisement
karenaaa

Untitled

Apr 5th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public class Map {
  2.  
  3. public static class Pair {
  4. private Object key, value;
  5.  
  6. public Pair(Object key, Object value) {
  7. this.key = key;
  8. this.value = value;
  9. }
  10. }
  11.  
  12. Pair[] pairs;
  13.  
  14. public Map(){
  15. pairs = new Pair[2];
  16. }
  17.  
  18. public Map(int size){
  19. pairs = new Pair[size];
  20. }
  21.  
  22. public void put(Object key, Object value) {
  23. for (int i = 0; i<pairs.length; i++) {
  24. if (key == pairs[i].key) {
  25. pairs[i].value = value;
  26. }
  27. }
  28. }
  29.  
  30. public Object get(Object key) {
  31.  
  32. for (int i=0; i<pairs.length; i++) {
  33. if (key == pairs[i].key) {
  34. return pairs[i].value;
  35. }
  36. }
  37.  
  38. return null;
  39. }
  40.  
  41. public void remove(Object key) {
  42.  
  43. }
  44.  
  45. public Object[] keys (){
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement