-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesertIslandPlaylist.java
More file actions
41 lines (34 loc) · 1.44 KB
/
desertIslandPlaylist.java
File metadata and controls
41 lines (34 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.ArrayList;
class Playlist {
public static void main(String[] args) {
ArrayList<String> desertIslandPlaylist = new ArrayList<String>();
desertIslandPlaylist.add("Love Stained");
desertIslandPlaylist.add("Colorado");
desertIslandPlaylist.add("Truth Hurts");
desertIslandPlaylist.add("Cranes in the sky");
desertIslandPlaylist.add("Slow down");
desertIslandPlaylist.add("Away Park");
desertIslandPlaylist.add("That girl");
// print curated selection
System.out.println(desertIslandPlaylist);
// check playlist length
System.out.println(desertIslandPlaylist.size());
// remove songs until 5 are left
desertIslandPlaylist.remove("That girl");
desertIslandPlaylist.remove("Colorado");
//Get the indices of the songs you want to swap.
int indexA = desertIslandPlaylist.indexOf("Love Stained");
int indexB = desertIslandPlaylist.indexOf("Slow down");
// Create a temporary variable to store the value of song a. (We’ll
call the songs a and b here.)
String tempA = "Love Stained";
// Rewrite the value at the index of a to the value of b.
desertIslandPlaylist.set(indexA, "Slow down");
desertIslandPlaylist.set(indexB, "Love Stained");
// Rewrite the value at the index of b to the value of the temporary
variable.
// print new playlist
System.out.println(desertIslandPlaylist.size());
System.out.println(desertIslandPlaylist);
}
}