This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to initialize array dynamically?
 
Similar Threads
Sorting an Array
how to convert byte array into short??
how to store map value in string array
How do you empty an array?
String array to arraylist