Advertisement
techno-

Circular

Nov 2nd, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. package e2;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.Spliterator;
  7. import java.util.function.Consumer;
  8.  
  9. public class Circular<String> extends TVRealityList<String> implements Iterator<String>{
  10.  
  11.     int pos= 0;
  12.  
  13.     public Circular(List<String> lista, boolean circular){
  14.         super(lista,circular);
  15.     }
  16.  
  17.     @Override
  18.     public boolean hasNext() {
  19.         if (lista.size()>1){
  20.             return true;
  21.         } else return false;
  22.     }
  23.  
  24.     @Override
  25.     public String next() {
  26.         pos++;
  27.         int poscorrecta = pos % lista.size();
  28.         String resultado = lista.get(poscorrecta);
  29.         return resultado;
  30.     }
  31.  
  32.     @Override
  33.     public void remove() {
  34.         Iterator.super.remove();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement