-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
  • 165,109
  • 17
  • 150
  • 199
Xaini Ali
  • 31
  • 4

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,403
  • 3
  • 22
  • 47
  • 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