wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to initialize array dynamically?" Watch "How to initialize array dynamically?" New topic
Author

How to initialize array dynamically?

Amruta Joshi
Greenhorn

Joined: Jul 08, 2005
Posts: 1
HI,
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 ]

Mani
Quaerendo Invenietis
Amol Fuke
Ranch Hand

Joined: Apr 08, 2005
Posts: 129
Amruta,

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)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to initialize array dynamically?
 
Similar Threads
How do you empty an array?
String array to arraylist
Sorting an Array
how to convert byte array into short??
how to store map value in string array