This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays" Watch "Arrays" New topic
Author

Arrays

Andrew Hartman
Greenhorn

Joined: Mar 18, 2004
Posts: 16
Where can I find information about arrays?
How do i create an array to store numbers? And can I change the size of the array using a variable such as arraySize?
Any help will be much appreciated
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
This code shows three ways to create an array of integers.

Any book on Java will explain arrays. Try Thinking in Java by Bruce Eckel, available free at bruceeckel.com.
You cannot change the size of an array. If you need to add elements to a "full" array, you must allocate a new array, then copy all elements from the old array to the new. The method System.arraycopy does this most efficiently.
Instead of using an array, prefer use of a collection class (such as ArrayList, which implements the interface List), which handles all this for you.
-Jeff-


Books: Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Arrays
 
Similar Threads
arrays
Swap sublist of an arraylist with the sublist of another arraylist
Array assignment
sum of two int arrays
generate random number into 2d arrays