• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arrays

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 799
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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-
 
reply
    Bookmark Topic Watch Topic
  • New Topic