Data Structures in Java: Part 15, The toArray Method, Part 1

Baldwin shows you how to use the simpler version of the overloaded toArray method that is declared in the Collection interface. He also explains why you need to exercise care when using the elements stored in the resulting array to avoid corrupting the state of the objects referred to by the elements in the collection.

provided by: 
Originally published at Internet.com


Java Programming, Lecture Notes #1378 * Preface * Preview * Discussion and Sample Program * Summary * What's Next -----------------------------------

Preface

A miniseries

This lesson is part of a miniseries on Java data structures and the Java Collections Framework. The first lesson in the miniseries was entitled Data Structures in Java: Part 1, Getting Started. The previous lesson was entitled Data Structures in Java: Part 14, The Comparator Interface, Part 6.

The purpose of this miniseries is to help you learn the essential features of Object-Oriented data structures in Java using the Collections Framework.

A sub-series

This is also the first lesson in a sub-series on the toArray method. The primary purpose of the lessons in this sub-series is to teach you how to use the overloaded toArray method, which is declared in the Collection interface.

Viewing tip

You may find it useful to open another copy of this lesson in a separate browser window. That will make it easier for you to scroll back and forth among the different listings while you are reading about them.

Supplementary material

I recommend that you also study the other lessons in my extensive collection of online Java tutorials. You will find those lessons published at Gamelan.com. However, as of the date of this writing, Gamelan doesn't maintain a consolidated index of my Java tutorial lessons, and sometimes they are difficult to locate there. You will find a consolidated index at Baldwin's Java Programming Tutorials.

Preview

In earlier lessons, I used the toArray method, declared in the Collection interface, to copy elements from a collection into an array. However, in those lessons, I didn't take the time to fully explain how to use the method. Also, I didn't fully explain the precautions that you need to take when you use the method...

Read article at Internet.com site
Regional Articles
- Data Structures in Java: Part 15, The toArray Method, Part 1 Alabama
- Data Structures in Java: Part 15, The toArray Method, Part 1 Alaska
- Data Structures in Java: Part 15, The toArray Method, Part 1 Arizona
- Data Structures in Java: Part 15, The toArray Method, Part 1 Arkansas
- Data Structures in Java: Part 15, The toArray Method, Part 1 California
- Data Structures in Java: Part 15, The toArray Method, Part 1 Colorado
- Data Structures in Java: Part 15, The toArray Method, Part 1 Connecticut
- Data Structures in Java: Part 15, The toArray Method, Part 1 DC
- Data Structures in Java: Part 15, The toArray Method, Part 1 Delaware
- Data Structures in Java: Part 15, The toArray Method, Part 1 Florida
- Data Structures in Java: Part 15, The toArray Method, Part 1 Georgia
- Data Structures in Java: Part 15, The toArray Method, Part 1 Hawaii
- Data Structures in Java: Part 15, The toArray Method, Part 1 Idaho
- Data Structures in Java: Part 15, The toArray Method, Part 1 Illinois
- Data Structures in Java: Part 15, The toArray Method, Part 1 Indiana
- Data Structures in Java: Part 15, The toArray Method, Part 1 Iowa
- Data Structures in Java: Part 15, The toArray Method, Part 1 Kansas
- Data Structures in Java: Part 15, The toArray Method, Part 1 Kentucky
- Data Structures in Java: Part 15, The toArray Method, Part 1 Louisiana
- Data Structures in Java: Part 15, The toArray Method, Part 1 Maine
- Data Structures in Java: Part 15, The toArray Method, Part 1 Maryland
- Data Structures in Java: Part 15, The toArray Method, Part 1 Massachusetts
- Data Structures in Java: Part 15, The toArray Method, Part 1 Michigan
- Data Structures in Java: Part 15, The toArray Method, Part 1 Minnesota
- Data Structures in Java: Part 15, The toArray Method, Part 1 Mississippi
- Data Structures in Java: Part 15, The toArray Method, Part 1 Missouri
- Data Structures in Java: Part 15, The toArray Method, Part 1 Montana
- Data Structures in Java: Part 15, The toArray Method, Part 1 Nebraska
- Data Structures in Java: Part 15, The toArray Method, Part 1 Nevada
- Data Structures in Java: Part 15, The toArray Method, Part 1 New Hampshire
- Data Structures in Java: Part 15, The toArray Method, Part 1 New Jersey
- Data Structures in Java: Part 15, The toArray Method, Part 1 New Mexico
- Data Structures in Java: Part 15, The toArray Method, Part 1 New York
- Data Structures in Java: Part 15, The toArray Method, Part 1 North Carolina
- Data Structures in Java: Part 15, The toArray Method, Part 1 North Dakota
- Data Structures in Java: Part 15, The toArray Method, Part 1 Ohio
- Data Structures in Java: Part 15, The toArray Method, Part 1 Oklahoma
- Data Structures in Java: Part 15, The toArray Method, Part 1 Oregon
- Data Structures in Java: Part 15, The toArray Method, Part 1 Pennsylvania
- Data Structures in Java: Part 15, The toArray Method, Part 1 Rhode Island
- Data Structures in Java: Part 15, The toArray Method, Part 1 South Carolina
- Data Structures in Java: Part 15, The toArray Method, Part 1 South Dakota
- Data Structures in Java: Part 15, The toArray Method, Part 1 Tennessee
- Data Structures in Java: Part 15, The toArray Method, Part 1 Texas
- Data Structures in Java: Part 15, The toArray Method, Part 1 Utah
- Data Structures in Java: Part 15, The toArray Method, Part 1 Vermont
- Data Structures in Java: Part 15, The toArray Method, Part 1 Virginia
- Data Structures in Java: Part 15, The toArray Method, Part 1 Washington
- Data Structures in Java: Part 15, The toArray Method, Part 1 West Virginia
- Data Structures in Java: Part 15, The toArray Method, Part 1 Wisconsin
- Data Structures in Java: Part 15, The toArray Method, Part 1 Wyoming

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML