Suppose you have a Book class in your project. Write a single statement that declares and initializes an ArrayList of Book objects named bookList. DO NOT include unneeded spaces in your answer.
How do?
Forgot to mention, this is Java.
>>57631095
install the supercomputer "gentoo"
You made 2 threads you insufferable faggot
ArrayList<Book> bookList = new ArrayList<>();
String fourthBook = bookList.get(3);
bookList.add(new Book("Elmo", "Happy"));
>>57631095
kys my man
>>57631095
>DO NOT include unneeded spaces in your answer.
Why?
>>57631095
lowkey hate array lists and have never found a useful way to use them
I just use regular arrays generally
>>57632866
Have you ever needed an array where you could increase the size dynamically?
That's what you use the ArrayList for.
>>57631095
List<Book> bookList = new ArrayList<>();
> DO NOT include unneeded spaces in your answer.
Please clarify.
>>57632901
I haven't, actually. That's the only advantage I could see to it but (at least in my courses) ive never needed it. I'm also not fond of how it only works for objects and not for primitive data types.
>>57631095List<Book> bookList = new ArrayList<>();
>>57632866
ArrayList uses an array to store the elements, but it has code that switches to a larger array if the original one runs out of slots. It also keeps track of how many items you've inserted so that you dont need to spend time writing that yourself.
>>57632866
i have arraylist too, but only because i like more the linkedlist one
>>57632964
you could always use the object version of the primitive data types, they are automatically converted and essentially the same (but one has fancy keywords and the other member functions)
>>57633016
However, if you always used the boxed object version, your program would run a lot slower, so you shouldn't do that.
>>57633016
Boxing and unboxing takes processor time and wastes memory. But if you don't process large amounts of numbers frequently it doesn't really matter.