Example usage for java.util ArrayList listIterator

List of usage examples for java.util ArrayList listIterator

Introduction

In this page you can find the example usage for java.util ArrayList listIterator.

Prototype

public ListIterator<E> listIterator(int index) 

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.

Usage

From source file:Main.java

public static void main(String args[]) {
    ArrayList<Integer> arrlist = new ArrayList<Integer>();

    arrlist.add(1);//from  ww  w. ja  va  2s  . com
    arrlist.add(2);
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

    ListIterator<Integer> iterator = arrlist.listIterator(2);
    while (iterator.hasNext()) {
        Integer i = iterator.next();
        iterator.remove();

    }
    System.out.println(arrlist);

}

From source file:com.wolvereness.bluebutton.crash.ExceptionMessage.java

public Report(final String text) {
    final ArrayList<String> lines;
    { // _LINES_/* www.  j  ava2 s  .  c  o m*/
        int i;
        if ((i = text.indexOf('\r')) != -1) {
            if (text.startsWith("\r\n", i)) { // StartsWith prevents OOB exception
                lines = Splitter.splitAll(text, "\r\n");
            } else {
                lines = Splitter.splitAll(text, '\r');
            }
        } else {
            lines = Splitter.splitAll(text, '\n');
        }
    } // _LINES_

    final ImmutableMap.Builder<Nodes, Node> nodes = ImmutableMap.builder();
    final ListIterator<String> it = lines.listIterator(lines.size() - 1);

    { // _DETAILS_
        int count = 0; // Number of lines with no "- " for sub-listing
        while (true) {
            String entry = it.previous();
            if (entry.startsWith(START)) {
                if (entry.startsWith(WORLD, 2)) {
                    continue; // Process this at end
                }

                final int colon = entry.indexOf(':');
                Nodes type = Nodes.valueOf(entry.substring(2, colon).toUpperCase().replace(' ', '_'));
                if (type == null) {
                    type = Nodes._NA;
                }
                final List<String> subList = lines.subList(it.nextIndex(), it.nextIndex() + count);
                final Node node = type.makeNode(entry.substring(colon + 1), subList);
                nodes.put(type, node);

                count = 0; // Reset count, as it is used for sub-listing
            } else if (entry.equals(DETAILS_START)) {
                {
                    final ArrayList<String> worlds = new ArrayList<String>();
                    while (it.hasNext()) {
                        entry = it.next();
                        if (entry.startsWith(WORLD_START)) {
                            worlds.add(entry);
                        }
                    }
                    nodes.put(Nodes.WORLD, Nodes.WORLD.makeNode(null, worlds));
                }

                while (!it.previous().equals(DETAILS_START)) {
                }
                if (!it.previous().equals("")) // NOTE_0- blank line preceding details check, see NOTE_0- below
                    throw new IllegalStateException("Expected blank line in " + lines.toString());
                while (!it.previous().startsWith(DESCRIPTION_START)) {
                }
                it.next(); // Description_start
                it.next(); // Blank line
                break; // We're done in the loop
            } else {
                count++;
            }
        }
    } // _DETAILS_

    { // _STACK_
        final LinkedList<ExceptionMessage> exceptions = new LinkedList<ExceptionMessage>();
        final List<StackTraceElement> stacks = new ArrayList<StackTraceElement>();
        final List<String> description = new ArrayList<String>();
        description.add(it.next()); // Initialize; first line is always first exception
        for (String entry = it.next(); !entry.equals(DETAILS_START); entry = it.next()) {
            // Read in all the exception information.
            // Apocalypse if the formating changes...
            if (entry.startsWith(STACK_START)) {
                // Normal stack element
                stacks.add(toStackTraceElement(entry));
            } else if (entry.startsWith(STACK_MORE_START)) {
                // "... n more" final line
                final ExceptionMessage previous = exceptions.getLast();
                final List<StackTraceElement> previousTrace = previous.getStackTrace();
                entry = entry.substring(STACK_MORE_START.length(), entry.length() - STACK_MORE_END.length());
                final int stackCount = Integer.valueOf(entry);
                stacks.addAll(previousTrace.subList(previousTrace.size() - stackCount, previousTrace.size()));
                exceptions.add(new ExceptionMessage(description, stacks));

                // Reset our counters
                description.clear();
                stacks.clear();
            } else if (entry.startsWith(CAUSED_START)) {
                // Finish old exception
                if (description.size() != 0) {
                    exceptions.add(new ExceptionMessage(description, stacks));
                    description.clear();
                    stacks.clear();
                }

                // New exception
                description.add(entry.substring(CAUSED_START.length()));
            } else {
                // Random description information
                description.add(entry);
            }
        }
        description.remove(description.size() - 1); // NOTE_0- There will be a blank line here, see NOTE_0- above
        if (description.size() != 0) {
            exceptions.add(new ExceptionMessage(description, stacks));
        }

        this.exceptions = ImmutableList.copyOf(exceptions);
    } // _STACK_

    while (!it.previous().startsWith(DESCRIPTION_START)) {
    } // This puts us on the line before the "description:"
    it.next(); // Push iterator for description_start to hit twice

    this.description = it.previous().substring(DESCRIPTION_START.length());

    { // _TIMESTAMP_
        final String timeStamp = it.previous().substring(TIME_START.length());
        Date time = null;
        try {
            time = (Date) DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.parseObject(timeStamp);
        } catch (final ParseException ex) {
            try {
                time = new SimpleDateFormat().parse(timeStamp);
            } catch (final ParseException e) {
            }
        }
        this.time = time == null ? new Date(0l) : time;
    } // _TIMESTAMP_

    it.previous(); // Blank line after joke
    this.fun = it.previous();

    this.nodes = nodes.build();
}

From source file:com.ludoscity.findmybikes.activities.NearbyActivity.java

@Override
public void onFavoriteSheetEditDone() {

    ArrayList<FavoriteItemBase> newlyOrderedFavList = new ArrayList<>();
    newlyOrderedFavList.addAll(mFavoriteRecyclerViewAdapter.getCurrentFavoriteList());

    DBHelper.dropFavoriteAll(this);
    mFavoriteRecyclerViewAdapter.clearFavoriteList();

    ListIterator<FavoriteItemBase> li = newlyOrderedFavList.listIterator(newlyOrderedFavList.size());

    while (li.hasPrevious()) {
        addFavorite(li.previous(), true, false);
    }//w ww.j a  v  a 2s. c o  m
}