Académique Documents
Professionnel Documents
Culture Documents
Method
Description
adds eto end of ArrayList a Inserts eat index i shifting elements up as necessary. , Sets the element at index ito e .
10/10/2012
e= agti .e() ora = atAry) ary .ora( era = atAryE] ary .ora([) Iterators ie = aieao( tr .trtr)
Returns the object at index i . Returns values in array of objects. The array parameter should be of the E class. Returns values in that array (or a larger array is allocated if necessary). Returns an Iterator for forward traversal.
l t r = a l s I e a o ( )Returns a ListIterator for forward / backward / modifying traversal, starting at ie .ittrtri .ittrtrasz() index i. Start from end with a l s I e a o ( . i e ) l t r = a l s I e a o ( Returns a ListIterator for forward / backward / modifying traversal. ie .ittrtr) Searching b= acnan() .otise i= aidxfe .neO() Returns true if ArrayList acontains e Returns index of first occurrence of e or -1 if not there. ,
i = a l s I d x f e Returns index of last occurrence of e or -1 if not there. .atneO() , Removing elements acer) .la( armv() .eoei removes all elements from ArrayList a Removes the element at position i .
a r m v R n e i Removes the elements from positions ithru j .eoeag(, . j ) Other i= asz( .ie) Returns the number of elements in ArrayList a .
2/3
10/10/2012
fr(trtrSrn>ie =aieao(;ie.aNx(; ){ o Ieao<tig tr .trtr) trhset) Sse.u.rnl(trnx() ytmotpitnie.et); } 4. L s I e a o < >- Allows traversal of the ArrayList, but it is more general than a simple Iterator, ittrtrE allowing inserts and deletes (although both are very slow for an ArrayList). It also allows bidirectional traversal. Works efficiently with both ArrayList and LinkedList.
Sorting
If the data in your ArrayList has a natural sorting order (ie, implements Comparable, as do String, Integer, ...), you can simply call the static C l e t o s s r ( method. This is a stable, guaranteed n log n sort. olcin.ot) Cletossr(orraLs) olcin.otyuAryit; If you want to choose a different sort criterion or your data doesn't implement xxxx, you will have to define a C omparator and pass that to the sort() method. Cletossr(orraLs,yuCmaao) olcin.otyuAryit oroprtr; C heck out C ollections for other useful utility methods.
3/3