Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

iterator Implementation

private class Itr implements Iterator<E> {
    int cursor;       // index of next element to return
    int lastRet = -1; // index of last element returned; -1 if no such
    int expectedModCount = modCount;

    public boolean hasNext() {
        return cursor != size;
    }

    @SuppressWarnings("unchecked")
    public E next() {
        checkForComodification();
        int i = cursor;
        if (i >= size)
            throw new NoSuchElementException();
        Object[] elementData = ArrayList.this.elementData;
        if (i >= elementData.length)
            throw new ConcurrentModificationException();
        cursor = i + 1;
        return (E) elementData[lastRet = i];
    }

    public void remove() {
        if (lastRet < 0)
            throw new IllegalStateException();
        checkForComodification();

        try {
            ArrayList.this.remove(lastRet);
            cursor = lastRet;
            lastRet = -1;
            expectedModCount = modCount;
        } catch (IndexOutOfBoundsException ex) {
            throw new ConcurrentModificationException();
        }
    }

    final void checkForComodification() {
        if (modCount != expectedModCount)
            throw new ConcurrentModificationException();
        }
    }
Comment

PREVIOUS NEXT
Code Example
Java :: spigot scoreboard objective 
Java :: force orientation programmatically android 
Java :: imagebutton get background color programmatically 
Java :: split string in / java 
Java :: Java continue with Nested Loop 
Java :: intent for youtube android stackoveroverflow 
Java :: java i/o streams 
Java :: adding entity to calenderfx 
Java :: initialize generic array java 
Java :: java union of sets 
Java :: how to find last digit in number by regex in java 
Java ::         System.out.println("Welcome to GeeksforGeeks"); 
Java :: Automatic Code Completion in NetBeans 
Java :: Java the implements this function will return a copy of the original String that has all characters replaced with plus signs ("+"), with the exception of word string appearances, which are left alone. 
Java :: Accesses Constructor of Abstract Classes 
Java :: constructors in java 
Java :: java declare 2d array with values 
Java :: java += 
Java :: using new to create arrays 
Java :: tests offline cypress 
Java :: Enlist Operations in ComboBox (Addition, Subtraction, Division, Multiplication in java 
Java :: what is a literal in java 
Java :: delete row entity jpa java 
Java :: android studio null 
Java :: what is this code (long millis=System.currentTimeMillis(); java.sql.Date date=new java.sql.Date(millis); 
Java :: tutorialedge working with docker 
Java :: Create hashmap from another maps java 
Java :: java program finish event 
Java :: newinstance in java giving exception 
Java :: convert kotlin to java online 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =