Reputation: 1
Hi i have a problem with this:
I want to get a book title(String) and release date(int) in the same index, but is it posible to do that? How can I solve this problem?
Upvotes: 0
Views: 36
Reputation: 2297
The best way to do this is to create a new Book object with fields title and year
Public Class Book{
private String title;
private int year;
public Book(String title, int year){
this.title = title;
this.year= year;
}
public String getTitle(){
return title;
}
public int getYear(){
return year;
}
}
And then store it in the list
LinkedList<Book> list = new LinkedList<Book>();
this way you can access all the book info with the index
Book book = list.get(2);
Upvotes: 1