Java (Collections) , . java.util.AbstractCollection. ( AbstractCollection , Collection).
:
- Set, SortedSet, HashSet,TreeSet ( )
- List, ArrayList,LinkedList,Vector ( , )
- Map, Sorted Map ( -)
, . (iterator). collection , :
Iterator iter = collection.iterator()
:
boolean hasNext()- , .
Object next() .
void remove() , , next().
, :
java.util.List components= java.util.Arrays.asList(this.getComponents());
for (Iterator iter = components.iterator();iter.hasNext();) {
Object elem = (Object) iter.next();
javax.swing.JOptionPane.showMessageDialog(null,": "+
elem.toString());
}
:
boolean add(Object obj) | ( ). true - . - . |
boolean addAll(Collection c) | . true , . |
void clear() | - . , , . |
boolean contains(Object obj) | true , obj. obj.equals(e) e, . |
boolean containsAll(Collection c) | true , c. |
boolean isEmpty() | true , , . |
Iterator iterator() | , . -, . . next() . |
boolean remove(Object obj) | obj. . true , , . |
boolean remove All(Collection c) | c. true , , . |
boolean retainAll(Collection c) | , c. |
int size() | . |
Object[] toArray() | , . . |
T[] toArray(T[n] a) | T, , . . n a, , . n , . a . |
String toString() | . , , . |
|
|
(Lists). , , . , .
List , :
list.get(i) list i.
list.indexOf(obj) - obj list. -1 .
list.listIterator(i) ListIterator, Iterator.
list.listIterator(i) i.
list.remove(i) i.
list.set(i,obj) i obj.
list.subList(i1,i2) , i1 i2.
List .
Collections:
Collections.addAll(c,e1,e2,,eN) - c e1,e2,,eN.
Collections.frequency(c,obj) obj c.
Collections.reverse(list) list ( ).
|
|
Collections.sort(list) . e1.compareTo(e2) e1 e2.
Collections .
Arrays
Arrays.asList(a) T, T[] a. , , , .