-2

Actually I want to do to set the pointer of arraylist to index which I will give, and my program will check if there's still elements then it will remove all from that index which I have given.

 public void removefromindex(int index)
 {
     for (int j = notes.size(); j >notes.size(); j++) 
     {
         notes.remove(j);
     } 
 }

 public void deleteAll(){
     for (Iterator<Note> it = notes.iterator(); it.hasNext(); ) 
     {
         Note note = it.next();
         it.remove();
     }
 }
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
Xaini Ali
  • 31
  • 4
  • `for (int j = notes.size(); j >notes.size(); j++)` <-- read that again, that makes no sense. – Tunaki Apr 29 '16 at 14:41

1 Answers1

2

You are giving an index and then not even using it and just looping through the ArrayList and removing some elements. What you are looking for is:

public void removefromindex(int index)
{
    notes.remove(index);
} 

To remove all of them, you can simply use:

public void deleteAll()
{
    notes.clear();
}
James
  • 1,471
  • 3
  • 23
  • 52
  • judging from the method name, I think he is trying to remove all items starting from the given index. In that case, a simple solution would be to use the iterator mechanism, and use `notes.listIterator(index)` instead of the default one. – n247s Apr 29 '16 at 14:49
  • 1
    @n247s you may be right actually, the question was a little difficult to understand. – James Apr 29 '16 at 14:53