1

i am pretty new to java can anyone help me to solve this problem: what i want is to print the content of the ArrayList but it gives me the address. Is there something simple and probably obvious I'm missing? any suggestion please? here's the code:

public class VideoGame {


private String title;
private int year;
private String rating;
private String[] platforms;

public VideoGame() {
}


public VideoGame(String title, int year, String rating,
                 String[] platforms) {
    this.title = title;
    this.year = year;
    this.rating = rating;
    this.platforms = platforms;
}
}

the main:

import java.util.*;

public class ArrayListExample {

public static void main(String[] args) {

    String[] platform1 = {"PS4"};
    String[] platform2 = {"3DS", "Wii U"};
    VideoGame game1 = new VideoGame("Battlefield1", 2001, "M", platform1);
    VideoGame game2 = new VideoGame("Pokemon Sun", 2016, "E", platform2);
    VideoGame game3 = new VideoGame("The legend of Zelda", 2017, "E", platform2);


    ArrayList<VideoGame> games = new ArrayList<>();
    games.add(game1);
    games.add(game2);
    games.add(game3);
    System.out.println(games);

}

}

this is the output : [VideoGame@2503dbd3, VideoGame@4b67cf4d, VideoGame@7ea987ac]

Hamza Belmellouki
  • 2,516
  • 1
  • 18
  • 39

0 Answers0