我是java新手可以任何人帮我解决这个问题:我想要的是打印ArrayList的内容,但它给了我的地址。 有什么简单的东西可能很明显我不见了吗?有什么建议吗? 这是代码:
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;
}
}
主要:
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);
}
}
这是输出:[VideoGame @ 2503dbd3,VideoGame @ 4b67cf4d,VideoGame @ 7ea987ac]