File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How to initialize array dynamically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to initialize array dynamically?" Watch "How to initialize array dynamically?" New topic

How to initialize array dynamically?

Amruta Joshi

Joined: Jul 08, 2005
Posts: 1
How to initializa array at run time without using for loop.?
I there any other method for that?
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
With out a loop!?

One Way:

Another Way:
You can use the fill() method in java.util.Arrays class, (but it internally uses a loop to assign the values).

Yet Another Way:
You can use while loops, if you don't want to use for loop

[ July 08, 2005: Message edited by: Mani Ram ]

Quaerendo Invenietis
Amol Fuke
Ranch Hand

Joined: Apr 08, 2005
Posts: 129

You can use something like this:

double[][] xAxisValues = new double[xValuesList.size()][];

This will initialize array xAxisValues of size xValuesList.size() where xValuesList is arraylist.

"There are no mistakes, only lessons"
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162
I did it my way (c):

[ July 08, 2005: Message edited by: George Bolyuba ]

SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
I agree. Here's the link:
subject: How to initialize array dynamically?