Hello,
I just want to know how to use arraylist in Java.
What I mean is, if I have 2 class(Book, and main class).
How to use the arraylist to construct new book?
Thank you
OK, I still don't quite understand what you're asking. What you're doing there is creating a bunch of Book objects and adding them to an ArrayList - that's not the same as using an ArrayList to create a Book.
There's clearly something missing from the second class listing (what's the class called? BookList?), and it's a bit strange that you've got a static ArrayList, which you then populate in what looks like it's supposed to be a constructor. So what is it you're trying to achieve?
Your booklist is an object. when you do System.out.println(booklist), you are calling the toString method of the ArrayList - which by default prints out (more or less) the memory address of the object.
What you probably want to do is call the toString() method on each object IN the array. You'll need to write a loop that iterates across all of them and prints out each book.
It's easy enough to write a method that does this, and you just pass it an ArrayList, so that it will work for ANY ArrayList.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
And remember: when you print out each Book, you either need to specifically print out the informatiohn you want (e.g. book.getTitle()), or you need to implement toString() so that when you do System.out.println(book) it does what you want.