Hi!
First of all, let me thank you for all the invaluable help and encouragement you give me on here each time I get stuck with my code.
This time, I’ve run into some difficulty while working through the ‘Desert Island Project’.
After successfully completing the first (easier) part of the unit, I started doing the tricky swapping exercise, and when I tried to run the fresh block of code, it wouldn’t run. I cleared the terminal and still no result.
That’s the point where you are supposed to see the same song listed twice in the ArrayList, after moving songB to the Index location of songA using the set() method.
I even watched the video walkthrough but the steps the developper took us through were exactly the same as mine.
I’m still racking my brains about where I could have gone wrong. It must be something obvious again I overlooked!
I’ll copypaste my code here below (sorry about the Italian titles, they are pieces of classical music I love)
import java.util.ArrayList;
class Playlist {
public static void main(String[] args) {
ArrayList<String> desertIslandPlaylist = new ArrayList<String>();
desertIslandPlaylist.add("Rompo i lacci!");
desertIslandPlaylist.add("Toccata e fuga");
desertIslandPlaylist.add("Sorge talora");
desertIslandPlaylist.add("Torbido intorno al cuore");
desertIslandPlaylist.add("Erfteute Ich, Herzen");
desertIslandPlaylist.add("Water Music");
desertIslandPlaylist.add("Music for the Royal Fireworks");
System.out.println(desertIslandPlaylist);
System.out.println(desertIslandPlaylist.size());
desertIslandPlaylist.remove(2);
desertIslandPlaylist.remove(4);
System.out.println(desertIslandPlaylist.size());
System.out.println(desertIslandPlaylist);
int indexA = desertIslandPLaylist.indexOf("Toccata e fuga");
int indexB = desertIslandPlaylist.indexOf("Torbido intorno al cuore");
String tempA = "Toccata e fuga";
desertIslandPlaylist.set(indexA, "Torbido intorno al cuore");
System.out.println(desertIslandPlaylist.size());
System.out.println(desertIslandPlaylist);
}
}