[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

ArrayList

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 1

File: Space.jpg (889KB, 4500x1759px) Image search: [Google]
Space.jpg
889KB, 4500x1759px
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.
>>
>>57631095
List<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.
Thread posts: 17
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.