Desert Island Playlist ArrayList project(switch array item order)
Thu Sep 29 2022 20:43:23 GMT+0000 (Coordinated Universal Time)
Saved by
@cruz
#javascript
import java.util.ArrayList;
class Playlist {
public static void main(String[] args) {
ArrayList<String> desertIslandPlaylist = new ArrayList <String>();
desertIslandPlaylist.add("Moon");
desertIslandPlaylist.add("Let it All Workout");
desertIslandPlaylist.add("Can't Get Close");
desertIslandPlaylist.add("Lord I Need You");
desertIslandPlaylist.add("Feel");
desertIslandPlaylist.add("24 hours");
desertIslandPlaylist.add("Bad News");
desertIslandPlaylist.add("Pure Souls");
desertIslandPlaylist.add("Come To Life");
//System.out.println(desertIslandPlaylist);
// System.out.println(desertIslandPlaylist.size());
desertIslandPlaylist.remove("Bad News");
desertIslandPlaylist.remove("Pure Souls");
desertIslandPlaylist.remove("Feel");
desertIslandPlaylist.remove("Lord I Need You");
//System.out.println(desertIslandPlaylist.size());
//Get the indices of the songs you want to swap.
int indexA = desertIslandPlaylist.indexOf("Let it All Workout");
int indexB = desertIslandPlaylist.indexOf("Moon");
//Create a temporary variable to store the value of song a. (We’ll call the songs a and b here.)
String tempA = "Let it All Workout";
//Rewrite the value at the index of a to the value of b.
desertIslandPlaylist.set(indexA, "Moon");
desertIslandPlaylist.set(indexB, "Let it All Workout");
System.out.println(desertIslandPlaylist.size());
System.out.println(desertIslandPlaylist);
}
}
content_copyCOPY
https://www.youtube.com/watch?v=WkY9PLNXpAs&ab_channel=Codecademy
Comments