Example usage for java.util LinkedList iterator

List of usage examples for java.util LinkedList iterator

Introduction

In this page you can find the example usage for java.util LinkedList iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this list in proper sequence.

Usage

From source file:Main.java

public static void main(String args[]) {
    LinkedList<String> ll = new LinkedList<String>();

    ll.add("A");/* w  w  w .j a va2  s. com*/
    ll.add("ja v a2s.com");
    ll.addLast("B");
    ll.add("C");

    Iterator<String> itr = ll.iterator();
    while (itr.hasNext()) {
        String element = itr.next();
        System.out.print(element + " ");
    }
}

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> lList = new LinkedList<String>();
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");

    Iterator itr = lList.iterator();
    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/*from   www .jav  a 2  s.com*/
}

From source file:Employee.java

public static void main(String args[]) {
    LinkedList<Employee> phonelist = new LinkedList<Employee>();

    phonelist.add(new Employee("A", "1"));
    phonelist.add(new Employee("B", "2"));
    phonelist.add(new Employee("C", "3"));

    Iterator<Employee> itr = phonelist.iterator();

    Employee pe;/*from w w  w .  j a  v  a 2  s  .c om*/
    while (itr.hasNext()) {
        pe = itr.next();
        System.out.println(pe.name + ": " + pe.number);
    }
    ListIterator<Employee> litr = phonelist.listIterator(phonelist.size());

    while (litr.hasPrevious()) {
        pe = litr.previous();
        System.out.println(pe.name + ": " + pe.number);
    }
}

From source file:LinkedListExample.java

public static void main(String[] args) {
    // Create a new LinkedList
    LinkedList<Integer> list = new LinkedList<Integer>();

    // Add Items to the array list
    list.add(new Integer(1));
    list.add(new Integer(2));
    list.add(new Integer(3));
    list.add(new Integer(4));
    list.add(new Integer(5));
    list.add(new Integer(6));
    list.add(new Integer(7));
    list.add(new Integer(8));
    list.add(new Integer(9));
    list.add(new Integer(10));

    // Use iterator to display the values
    for (Iterator i = list.iterator(); i.hasNext();) {
        Integer integer = (Integer) i.next();
        System.out.println(integer);
    }/* w  ww  .java 2 s  .  c  o m*/

    // Remove the element at index 5 (value=6)
    list.remove(5);

    // Set the value at index 5, this overwrites the value 7
    list.set(5, new Integer(66));

    // Use the linked list as a queue:
    // add an object to the end of the list (queue)
    // remove an item from the head of the list (queue)
    list.addLast(new Integer(11));
    Integer head = (Integer) list.removeFirst();
    System.out.println("Head: " + head);

    // Use iterator to display the values
    for (Iterator i = list.iterator(); i.hasNext();) {
        Integer integer = (Integer) i.next();
        System.out.println(integer);
    }
}

From source file:com.apipulse.bastion.Main.java

public static void main(String[] args) throws IOException, ClassNotFoundException {
    log.info("Bastion starting. Loading chains");
    final File dir = new File("etc/chains");

    final LinkedList<ActorRef> chains = new LinkedList<ActorRef>();
    for (File file : dir.listFiles()) {
        if (!file.getName().startsWith(".") && file.getName().endsWith(".yaml")) {
            log.info("Loading chain: " + file.getName());
            ChainConfig config = new ChainConfig(IOUtils.toString(new FileReader(file)));
            ActorRef ref = BastionActors.getInstance().initChain(config.getName(),
                    Class.forName(config.getQualifiedClass()));
            Iterator<StageConfig> iterator = config.getStages().iterator();
            while (iterator.hasNext())
                ref.tell(iterator.next(), null);
            chains.add(ref);//from   w w w  . ja va  2  s  . c o  m
        }
    }
    SpringApplication app = new SpringApplication();
    HashSet<Object> objects = new HashSet<Object>();
    objects.add(ApiController.class);
    final ConfigurableApplicationContext context = app.run(ApiController.class, args);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                log.info("Bastion shutting down");
                Iterator<ActorRef> iterator = chains.iterator();
                while (iterator.hasNext())
                    iterator.next().tell(new StopMessage(), null);
                Thread.sleep(2000);
                context.stop();
                log.info("Bastion shutdown complete");
            } catch (Exception e) {
            }
        }
    });
}

From source file:net.semanticmetadata.lire.solr.AddImages.java

public static void main(String[] args) throws IOException, InterruptedException {
    BitSampling.readHashFunctions();//ww w . j ava2 s .  c o m
    LinkedList<Thread> threads = new LinkedList<Thread>();
    for (int j = 10; j < 21; j++) {
        final int tz = j;
        Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    List<File> files = FileUtils
                            .getAllImageFiles(new File("D:\\DataSets\\WIPO-US\\jpg_us_trim\\" + tz), true);
                    int count = 0;
                    BufferedWriter br = new BufferedWriter(new FileWriter("add-us-" + tz + ".xml", false));
                    br.write("<add>\n");
                    for (Iterator<File> iterator = files.iterator(); iterator.hasNext();) {
                        File file = iterator.next();
                        br.write(createAddDoc(file).toString());
                        count++;
                        //                            if (count % 1000 == 0) System.out.print('.');
                    }
                    br.write("</add>\n");
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                }
            }
        };
        t.start();
        threads.add(t);
    }
    for (Iterator<Thread> iterator = threads.iterator(); iterator.hasNext();) {
        Thread next = iterator.next();
        next.join();
    }
}

From source file:Main.java

public static <V> void splice(LinkedList<V> list, Iterator<V> iterator, LinkedList<V> list2, V v) {
    list2.remove(v);/* w w  w .  j  av  a 2s .  co m*/
    assert (iterator.equals(list.iterator()));

    list.addFirst(v);
}

From source file:Main.java

public static int[] parseIntList(String list) {
    if (list == null)
        return null;

    intMatch.reset(list);/*  www  . j ava2s .com*/

    LinkedList<Integer> intList = new LinkedList<Integer>();
    while (intMatch.find()) {
        String val = intMatch.group();
        intList.add(Integer.valueOf(val));
    }

    int[] retArr = new int[intList.size()];
    Iterator<Integer> it = intList.iterator();
    int idx = 0;
    while (it.hasNext()) {
        retArr[idx++] = ((Integer) it.next()).intValue();
    }

    return retArr;
}

From source file:Main.java

public synchronized static float[] parseFloatList(String list) {
    if (list == null)
        return null;

    fpMatch.reset(list);//from  w w w .  jav  a 2 s. c  o m

    LinkedList<Float> floatList = new LinkedList<Float>();
    while (fpMatch.find()) {
        String val = fpMatch.group(1);
        floatList.add(Float.valueOf(val));
    }

    float[] retArr = new float[floatList.size()];
    Iterator<Float> it = floatList.iterator();
    int idx = 0;
    while (it.hasNext()) {
        retArr[idx++] = ((Float) it.next()).floatValue();
    }

    return retArr;
}

From source file:Main.java

/**
 * Scans an input string for double values.  For each value found, places
 * in a list.  This method regards any characters not part of a floating
 * point value to be seperators.  Thus this will parse whitespace seperated,
 * comma seperated, and many other separation schemes correctly.
 *///from w ww . j a v a2 s  .  c  om
public synchronized static double[] parseDoubleList(String list) {
    if (list == null)
        return null;

    fpMatch.reset(list);

    LinkedList<Double> doubList = new LinkedList<Double>();
    while (fpMatch.find()) {
        String val = fpMatch.group(1);
        doubList.add(Double.valueOf(val));
    }

    double[] retArr = new double[doubList.size()];
    Iterator<Double> it = doubList.iterator();
    int idx = 0;
    while (it.hasNext()) {
        retArr[idx++] = ((Double) it.next()).doubleValue();
    }

    return retArr;
}