This Java program is designed to practice working with ArrayList and basic Java functionality such as arrays, loops, and data manipulation. The program simulates creating a playlist of favorite songs and then refining it to a "Desert Island Playlist" — a smaller list of must-have songs.
- Create an array of favorite songs
- Print individual songs from the array
- Add songs to an
ArrayList - Remove specific songs from the playlist
- Swap songs within the playlist using the
set()method - Practice the use of the
size(),remove(), andindexOf()methods forArrayList
-
Favorite Songs Array: The program begins by creating a
String[]array of favorite songs. It prints a few of the songs from this array. -
Desert Island Playlist: An
ArrayListcalleddesertIslandPlaylistis created, initially populated with a few songs. Then, songs from thefavoriteSongsarray are added to this playlist usingaddAll(). -
Modifying the Playlist: Several songs are removed from the playlist using the
remove()method to simulate reducing the playlist for a desert island scenario. -
Swapping Songs: Finally, the program demonstrates how to swap two songs by finding their indices with
indexOf()and usingset()to replace the songs in the playlist.