Java by API/java.util/LinkedHashMap — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:10, 31 мая 2010
Содержание
- 1 LinkedHashMap: clear()
- 2 LinkedHashMap: containsKey(Object key)
- 3 LinkedHashMap: containsValue(Object value)
- 4 LinkedHashMap: get(Object key)
- 5 LinkedHashMap: put(K key, V value)
- 6 LinkedHashMap: remove(Object key)
- 7 LinkedHashMap: size()
- 8 LinkedHashMap: values()
- 9 new LinkedHashMap()
- 10 new LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
LinkedHashMap: clear()
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<String,String> lHashMap = new LinkedHashMap<String,String>();
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
lHashMap.clear();
System.out.println(lHashMap.size());
}
}
LinkedHashMap: containsKey(Object key)
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<String,String> lHashMap = new LinkedHashMap<String,String>();
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
boolean blnExists = lHashMap.containsKey("3");
System.out.println(blnExists);
}
}
LinkedHashMap: containsValue(Object value)
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<String,String> lHashMap = new LinkedHashMap<String,String>();
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
boolean blnExists = lHashMap.containsValue("Two");
System.out.println(blnExists);
}
}
LinkedHashMap: get(Object key)
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<String,Integer> lHashMap = new LinkedHashMap<String,Integer>();
lHashMap.put("One", new Integer(1));
lHashMap.put("Two", new Integer(2));
Object obj = lHashMap.get("One");
System.out.println(obj);
}
}
LinkedHashMap: put(K key, V value)
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<String,String> lHashMap = new LinkedHashMap<String,String>();
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
boolean blnExists = lHashMap.containsKey("3");
System.out.println(blnExists);
}
}
LinkedHashMap: remove(Object key)
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<String,String> lHashMap = new LinkedHashMap<String,String>();
System.out.println(lHashMap.size());
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
System.out.println(lHashMap.size());
Object obj = lHashMap.remove("2");
System.out.println(lHashMap.size());
}
}
LinkedHashMap: size()
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<String,String> lHashMap = new LinkedHashMap<String,String>();
System.out.println(lHashMap.size());
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
System.out.println(lHashMap.size());
Object obj = lHashMap.remove("2");
System.out.println(lHashMap.size());
}
}
LinkedHashMap: values()
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<String,String> lHashMap = new LinkedHashMap<String,String>();
lHashMap.put("1", "One");
lHashMap.put("2", "Two");
lHashMap.put("3", "Three");
Collection c = lHashMap.values();
Iterator itr = c.iterator();
while (itr.hasNext()){
System.out.println(itr.next());
}
}
}
new LinkedHashMap()
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<Integer, Integer> linkedMap = new LinkedHashMap<Integer, Integer>();
for (int i = 0; i < 10; i++) {
linkedMap.put(i, i);
}
System.out.println(linkedMap);
// Least-recently used order:
linkedMap = new LinkedHashMap<Integer, Integer>(16, 0.75f, true);
for (int i = 0; i < 10; i++) {
linkedMap.put(i, i);
}
System.out.println(linkedMap);
for (int i = 0; i < 7; i++)
System.out.println(linkedMap.get(i));
System.out.println(linkedMap);
}
}
new LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
import java.util.LinkedHashMap;
public class Main {
public static void main(String[] args) {
LinkedHashMap<Integer, Integer> linkedMap = new LinkedHashMap<Integer, Integer>();
for (int i = 0; i < 10; i++) {
linkedMap.put(i, i);
}
System.out.println(linkedMap);
// Least-recently used order:
linkedMap = new LinkedHashMap<Integer, Integer>(16, 0.75f, true);
for (int i = 0; i < 10; i++) {
linkedMap.put(i, i);
}
System.out.println(linkedMap);
for (int i = 0; i < 7; i++)
System.out.println(linkedMap.get(i));
System.out.println(linkedMap);
}
}