O'Reilly logo

Real World XML by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Arrays in Java

Simple data types of the kind we saw in the previous section are fine for storing single data items, but data is often more complex. Like JavaScript, Java supports arrays as well. Here's an example. In this case, I'll store the balances in customers' charge accounts in an array named chargesDue. I start by declaring that array, making it of type double:

public class ch10_04 
{
    public static void main(String[] args)
    {
        double chargesDue[];
    .
    .
    .

Besides declaring the array, you have to allocate the number of elements you want the array to hold. You do that using the new operator:

public class ch10_04 
{
    public static void main(String[] args)
    {
        double chargesDue[];
        chargesDue = new double[100];
    .
    .
    .

You can combine the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required