Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 13, 2020 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/944ccd663913ef257f71bfa6906b5a81 to your computer and use it in GitHub Desktop.
Save codecademydev/944ccd663913ef257f71bfa6906b5a81 to your computer and use it in GitHub Desktop.
Codecademy export
import java.util.ArrayList;
class Playlist {
public static void main(String[] args) {
ArrayList<String> desertIslandPlaylist = new ArrayList<String>();
desertIslandPlaylist.add("Jee Lay zara");
desertIslandPlaylist.add("ya tou barbad kar dy");
desertIslandPlaylist.add("Jis ki biwi moti");
desertIslandPlaylist.add("Intaha ho gae intizar ki");
desertIslandPlaylist.add("kya khabar kya pata");
desertIslandPlaylist.add("kabhi kabhi mery dil mein");
System.out.println("Before Swapping Playlist: ");
System.out.println(desertIslandPlaylist);
System.out.println("Size of playlist before : " + desertIslandPlaylist.size());
desertIslandPlaylist.remove(5);
System.out.println("Size of playlist after removing : " + desertIslandPlaylist.size());
int song1 = desertIslandPlaylist.indexOf("Jis ki biwi moti");
int song2 = desertIslandPlaylist.indexOf("Jee Lay zara");
String tempVar = desertIslandPlaylist.get(song1);
desertIslandPlaylist.set(song1, desertIslandPlaylist.get(song2));
desertIslandPlaylist.set(song2, tempVar);
System.out.println("After Swapping new Playlist: ");
System.out.println(desertIslandPlaylist);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment