Looping with an ArrayList
Code :
for(int i = 0; i < songList.size(); i++)
{
ui.displaySongs(songList.get(i), songList);
}
SongList is an ArrayList.
What I would like to do, is loop the variable "i", which I am using as the index for elements of an arraylist, but not loop the call to the method displaySongs. (which is in another class for user interface)
This loop is printing my code for the amount of elements in the arrayList, when I would only like to print once for every 4 elements.
My problem is that if I were to be adding 8 elements to the arraylist through a user interface,
it would display the formatted statement 8 times.
tl;dr: How can I loop the index for the get method of ArrayList, but not loop my display for the size of the arraylist.
Re: Looping with an ArrayList
I'm not sure I understand your question. It sounds like you want your ui to display a subset of your songlist...if that is the case, rewrite ui.displaySongs so that all you need is to pass the List and a start end index to display (or an array of values to display).
Re: Looping with an ArrayList
Quote:
I would only like to print once for every 4 elements.
Try using the modulus operator with i to detect every 4th element.
Or increment i by 4 vs by 1 (i++)
I don't understand the rest of your requirements.
Re: Looping with an ArrayList
Quote:
Originally Posted by
EmSaint
I would only like to print once for every 4 elements.
Code :
for(int i = 0; i < songList.size(); i += 4)
db