Vala List Example

This sample uses the List class from GLib. There is also various container classes in libgee, which are often easier to use or more powerful. See ../GeeSamples

int main (string[] args) {
    var list = new List<string> ();
    list.append ("one");
    list.append ("two");
    list.append ("three");
    
    stdout.printf ("list.length () = %u\n", list.length ());

    // Traditional iteration
    for (int i = 0; i < list.length (); i++) {
        stdout.printf ("%s\n", list.nth_data (i));
    }

    // Comfortable iteration
    foreach (string element in list) {
        stdout.printf ("%s\n", element);
    }

    return 0;
}

Compile and Run

$ valac -o list list.vala
$ ./list


Vala/Examples

Projects/Vala/ListSample (last edited 2013-11-22 16:48:25 by WilliamJonMcCann)