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;
- private int k;
- private int pos= 0;
- private int poscorrecta;
- public Circular(List<String> lista, int k){
- this.lista=lista;
- this.k=k;
- }
- @Override
- public boolean hasNext() {
- if (lista.size()>1){
- return true;
- } else return false;
- }
- @Override
- public String next() {
- pos=pos+k-1;
- poscorrecta = pos % lista.size();
- System.out.println("la pos es " + (poscorrecta+1));
- String resultado = lista.get(poscorrecta);
- return resultado;
- }
- @Override
- public void remove() {
- lista.remove(poscorrecta);
- if(pos> lista.size()){
- pos=0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement