/* * Primitive Collections for Java. * Copyright (C) 2003 Søren Bak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import bak.pcj.list.IntList; import bak.pcj.list.IntArrayList; import bak.pcj.list.IntListIterator; /** * This examplifies the operations of a list. * * @author Søren Bak * @version 1.0 2003/14/1 */ public class ListExample { public static void main(String[] args) { IntList s = new IntArrayList(); // Adding elements to the end s.add(1); // s=[1] s.add(2); // s=[1,2] // Inserting elements at positions s.add(2, 3); // s=[1,2,3] s.add(0, 0); // s=[0,1,2,3] s.add(1, 10); // s=[0,10,1,2,3] // Removing elements at positions s.removeElementAt(1); // s=[0,1,2,3] // Removing elements by value s.remove(2); // s=[0,1,3] // Updating elements s.set(2, 2); // s=[0,1,2] s.set(0, -1); // s=[-1,1,2] // Searching for elements int v; v = s.indexOf(1); // v=1 v = s.indexOf(2); // v=2 v = s.indexOf(10); // v=-1 // Adding collections at positions IntArrayList t = new IntArrayList(); t.add(10); // t=[10] t.add(20); // t=[10,20] t.add(30); // t=[10,20,30] s.addAll(1, t); // s=[-1,10,20,30,1,2] } }