Ok, I began typing my second array....when I reach.....""Array." once I type in the period, a small list of java methods come up. A LOT of copyOf comes up. Which one should I use?
Printable View
It doesn't matter. Simply type the method name and then add your 2 parameters: your array and an int indicating the length of the new ("copy") array.
Hmmm, when choosing a copyOf method, I chose the very first option...followed thru with code...and no matter what I seem to do....I get a squiggly line underneath my second parameter. Whether I choose, book.size, book.length(doesnt recognize lenght)....I get syntax error. Argh, I feel so close!!!
Code :ArrayList <PhoneBookEntry> book = new ArrayList <PhoneBookEntry>(); <-----my first arraylist ArrayList <PhoneBookEntry> copiedBook = new ArrayList <PhoneBookEntry>(); <------ the 2nd list in which I wish to copy the first copiedBook = Arrays.copyOf(book, book.size()); <-------------------------the squiggly line appears under the phrase book.size.
I thought you said you wanted to make a copy of an array but in your code you are using ArrayLists. make up your mind.
I do want to copy the contents of one ArrayList, into another. I guess I didn't see what I wrote.
So a lot of time has been wasted due to you not posting correct information. The ArrayList class has a clone method but you will still have the same issues that I mentioned in reply 15.