Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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.
Improving the world one idiot at a time!
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!!!
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.
Improving the world one idiot at a time!
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.
Improving the world one idiot at a time!