This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to initialize array dynamically?

 
Amruta Joshi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
How to initializa array at run time without using for loop.?
I there any other method for that?
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Amol Fuke
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it my way (c):


[ July 08, 2005: Message edited by: George Bolyuba ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic