Created: 2023-09-03 20:54
Status: #concept
Subject: Programming
Tags: java.util Java Java Interface java.util.ArrayList java.util.Set java.util.List
java.util.Collection
It is a Java Interface that is implemented by many data structure classes.
- all subclasses implementing it inherit the
for-each
loop behavior.
All Known Implementing Classes:
AbstractCollection, AbstractList, AbstractQueue, AbstractSequentialList, AbstractSet, ArrayBlockingQueue, ArrayDeque, ArrayList, AttributeList, BeanContextServicesSupport, BeanContextSupport, ConcurrentHashMap.KeySetView, ConcurrentLinkedDeque, ConcurrentLinkedQueue, ConcurrentSkipListSet, CopyOnWriteArrayList, CopyOnWriteArraySet, DelayQueue, EnumSet, HashSet, JobStateReasons, LinkedBlockingDeque, LinkedBlockingQueue, LinkedHashSet, LinkedList, LinkedTransferQueue, PriorityBlockingQueue, PriorityQueue, RoleList, RoleUnresolvedList, Stack, SynchronousQueue, TreeSet, Vector
Map<String, String> translations = new HashMap<>();
translations.put("ganbatte", "good luck");
translations.put("hai", "yes");
Set<String> keys = translations.keySet();
Collection<String> keyCollection = keys;
System.out.println("Keys:");
for (String key: keyCollection) {
System.out.println(key);
}
System.out.println();
System.out.println("Values:");
Collection<String> values = translations.values();
for (String value: values) {
System.out.println(value);
}
Keys:
ganbatte
hai
Values:
yes
good luck