Where is wrong ? desertIsland Playlist

import java.util.ArrayList;

class Playlist {
  
  public static void main(String[] args) {
    ArrayList<String> desertIslandPlaylist =  new ArrayList<String>();
    desertIslandPlaylist.add("Hey Jude");
    desertIslandPlaylist.add("In My Life");
     desertIslandPlaylist.add("A Day In The Life");
      desertIslandPlaylist.add("Here Comes The Sun");
       desertIslandPlaylist.add("Yesterday");
        desertIslandPlaylist.add("Yaama Yaama");
        System.out.println(desertIslandPlaylist);
        System.out.println(desertIslandPlaylist.size());
        desertIslandPlaylist.remove(3);
        desertIslandPlaylist.size();
        System.out.println(desertIslandPlaylist);
        int indexA = desertIslandPlaylist.indexof("Yaama Yaama");
        int indexB = desertIslandPlaylist.indexof("Hey Jude");
        
        String tempA = "Yamma Yamma";
        desertIslandPlaylist.set(indexB,"Yaama Yaama");
        desertIslandPlaylist.set(indexA, "Hey Jude");

  }
  
}

What is wrong? Please be more specific with your question. If you’re getting an error, please post it. If the code isn’t working as you expect, how so?

Dumping this into a compiler, just some things I’m seeing:

  • “Playlist” should be declared as a public class
  • the calls to “indexof” should be “indexOf”

When I write java Playlist in the terminal there output was only 6 but not print playlist , Even after the mentation System.out.println(desertIslandPlaylist); will you please help me to get out of this problem.

I don’t quite understand. When I run the code, I get this output:


Is that not that output that you’re looking for?

Yeah, I’m looking for that output , But I didn’t get it , that’s why I posted question ? where is wrong in my code!!

Try pressing the save button. If that doesn’t work, then I’m afraid I may be out of ideas…

Getting same things again , Don’t know why ?? Will you please check it once .

1 Like

Can you post a screenshot of all the code, please?

I don’t know how but now I got output… .SS is attached . I get the same output that u shared with me earlier.

1 Like

Oh well; all’s well that ends well, I suppose-happy coding!