
Como mostrar una lista
Publicado por Pedro (7 intervenciones) el 25/09/2022 16:37:19
Buenas estoy intentando mostar esta lista por el terminal pero es imposible. He probado con lo siguiente un for each y un print out para que me muestre la lista entera, pero solo me muestra la prima columna la de titulo del libro. La lista viene formada desde aquí.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class Book {
public final String name;
public final String author;
public final String genre;
public final int pages;
// constructor
public Book(String name, String author, String genre, int pages) {
this.name = name;
this.author = author;
this.genre = genre;
this.pages = pages;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
public String getGenre() {
return genre;
}
public int getPages() {
return pages;
}
@Override
public String toString() {
return name;
}
public static String stream() {
// TODO Auto-generated method stub
return null;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
List<Book> books = Arrays.asList(
new Book("Harry Potter and the chamber of secrets", "J.K Rowling", "Fantasy", 341),
new Book("Lord of the rings, the two tower", "J.R.R Tolkien", "Fantasy", 352),
new Book("A study in Scarlet", "Arthur Conan Doyle", "Mistery", 96),
new Book("The hunger games", "Suzanne Collins", "Science Fiction", 374),
new Book("Cujo", "Stephen King", "Mystery", 309));
System.out.println(books);
books.forEach(System.out::println);
)
Valora esta pregunta


0