- Is there a better way to add a list to another existing list than what I have coded in the add method ?
-
Is the way to remove a list of songs from a playlist correct or am I going to hit concurrent modification exception ?
class Playlist { List<Song> playList; public void addSongs(List<Song> songs) { for(Song s:songs) playList.add(s); } public void removeSongs(List<Song> songs) { for(Song s:songs) if(playList.contains(s)) playList.remove(s); } }
Is there a better way to add a list to another existing list than
Share
To add all the elements from one list to another, use;
List.addAllTo remove all the elements from one list from another use;
List.removeAll