Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package e2;
- import java.util.Iterator;
- import java.util.List;
- public class Circular implements Iterator<String>{
- private List<String> lista;
- int pos= 0;
- public Circular(List<String> lista){
- this.lista=lista;
- }
- @Override
- public boolean hasNext() {
- if (lista.size()>1){
- return true;
- } else return false;
- }
- @Override
- public String next() {
- pos++;
- int poscorrecta = pos % lista.size();
- String resultado = lista.get(poscorrecta);
- return resultado;
- }
- @Override
- public void remove() {
- Iterator.super.remove();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement