ArrayList<G>

Реализация массива изменяемого размера c интерфейсом List .
Массив автоматически увеличивается при необходимости.
Когда использовать
Эта реализация хороша для редко изменяемых данных. Поскольку данные хранятся в массиве, эта структура не подходит для сильно изменяемых данных. альтернативная реализация см. LinkedList .
List Example
using Gee;
void main () {
    var list = new ArrayList<int> ();
    list.add (1);
    list.add (2);
    list.add (5);
    list.add (4);
    list.insert (2, 3);
    list.remove_at (3);
    foreach (int i in list) {
        stdout.printf ("%d\n", i);
    }
    list[2] = 10;                       // same as list.set (2, 10)
    stdout.printf ("%d\n", list[2]);    // same as list.get (2)
}Compile and Run
$ valac --pkg gee-0.8 gee-list.vala
$ ./gee-listYou can use any type fitting into the size of a pointer (e.g. int, bool, reference types) directly as generic type argument: <bool>, <int>, <string>, <MyObject>. Other types must be "boxed" by appending a question mark: <float?>, <double?>, <MyStruct?>. The compiler will tell you this if necessary.
Content:
Properties:
- public EqualDataFunc<G> equal_func { get; } The elements' equality testing function. 
Creation methods:
- public ArrayList (owned EqualDataFunc<G>? equal_func = null) Constructs a new, empty array list. 
- public ArrayList.wrap (owned G[] items, owned EqualDataFunc<G>? equal_func = null) Constructs a new array list based on provided array. 
Methods:
- public override bool @foreach (ForallFunc<G> f) 
- public bool add_all (Collection<G> collection) 
- public override BidirListIterator<G> bidir_list_iterator () Returns a BidirListIterator that can be used for iteration over this list. 
- public override void clear () Removes all items from this collection. Must not be called on read-only collections. 
- public override ListIterator<G> list_iterator () Returns a ListIterator that can be used for iteration over this list. 
Полный список коллекций см здесь.
Last updated
Was this helpful?