Advertisement
techno-

Circular

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