package com.rr.java.e3_Map;
/**
* 键值对
* Created by isaac_gu on 2016/4/20.
*/
public class MyMap {
private Entry[] arr = new Entry[1000];
private int size;
public void put(Object key, Object value) {
for (int i = 0; i < size; i++) {
if (arr[i].key.equals(key)) {
arr[i].value = value;
return;
}
}
arr[size++] = new Entry(key, value);
}
public Object get(Object key) {
for (int i = 0; i < size; i++) {
if (arr[i].key.equals(key)) {
return arr[i].value;
}
}
return null;
}
public int size() {
return size;
}
public boolean containKey(Object key) {
for (int i = 0; i < size; i++) {
if (arr[i].key.equals(key)) {
return true;
}
}
return false;
}
public boolean containValue(Object value) {
for (int i = 0; i < size; i++) {
if (arr[i].value.equals(value)) {
return true;
}
}
return false;
}
private class Entry {
Object key;
Object value;
public Entry(Object key, Object value) {
this.key = key;
this.value = value;
}
}
}
转载于:https://my.oschina.net/u/659286/blog/663156