Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
JavaAPI
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Collections== Seit Java 1.2 gibt es das Collection API. Seitdem gibt es die Interfaces sowie die entsprechenden implementations: *[[JavaAPI#Collection|Collection]] *[[JavaAPI#List|List]] ([[JavaAPI#LinkedList|LinkedList]], [[JavaAPI#ArrayList|ArrayList]], [[JavaAPI#Vector|Vector]], [[JavaAPI#Stack|Stack]]) *Set ([[JavaAPI#HashSet|HashSet]], [[JavaAPI#TreeSet|TreeSet]]) *[[JavaAPI#Map|Map]] (HashMap, LinkedHashMap, TreeMap) ===Traversing=== ====extended for==== s. [[JavaLanguage#for|extended for]] ====Iterators/Enumerations==== Für Iteratoren definiert die Java-Bibliothek zwei unterschiedliche Schnittstellen. Das hat historische Gründe. Die Schnittstelle Enumeration gibt es seit den ersten Java-Tagen; die Schnittstelle Iterator gibt es seit Java 1.2, seit der Collection-API. Der Typ Iterator ist jedoch deutlich weiter verbreitet. Beiden Schnittstellen ist eine Funktion gemeinsam, die das nächste Element erfragt, und eine Funktion, die ermittelt, ob es überhaupt ein nächstes Element gibt. So wandert der Iterator einen Datengeber (in der Regel eine Datenstruktur) Element für Element ab. Die Namen der Operationen unterscheiden sich in den Schnittstellen ein wenig und sind beim Iterator kürzer. for (java.util.Iterator<Type> i = o.getCollection().iterator();ii.hasNext();) { Type t = ii.next(); } Die Schnittstelle Iterator bietet eine Möglichkeit, die Enumeration nicht bietet. Das zuletzt aufgezählte Element lässt sich aus dem zugrunde liegenden Container mit remove() entfernen. Vor dem Aufruf muss jedoch next() das zu löschende Element als Ergebnis geliefert haben. Eine Enumeration kann die aufgezählte Datenstruktur grundsätzlich nicht verändern. Sie stellt quasi eine Pointer-Liste darstellen und es aus diesem Grund gefährlich ist, die Quelle zu modifizieren, während man interiert. In der Regel löst dies eine ConcurrentModificationException aus. import java.util.Enumeration; for (Enumeration e = ds.elements(); e.hasMoreElements();) System.out.println(e.nextElement()); ===ArrayList=== dynamic linear (ordered) list, index starts with 0 * <code>add(<Element>)</code> adds elements to the end of the list ===Bitsets=== ===Collection=== The Collection interface is used to pass around collections of objects where maximum generality is desired. For traversing see [[JavaAPI#Traversing|Traversing]]. ===HashSet=== unordered set of elements with no doublettes ===Hashtable=== associative memory ===LinkedList=== doubled chained list ===List=== import java.util.List; List<C> l = new ArrayList<C>(); C c = l.get(0); // 0-based index ===Map=== import java.util.Map; A Map is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most one value. ===Properties=== specialized hashtable for strings ===Queues=== ===Stack=== LIFO principle ===TreeSet=== like HashSet but ordered ===Vector=== The Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. v = new java.util.Vector(); v.add("xyz"); for (java.util.Enumeration e = v.elements(); e hasMoreElements();) { e.nextElement(); }
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width