This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays

 
Andrew Hartman
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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-
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic