Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

change number of objects dynamically  RSS feed

 
usha mocherla
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I am trying to create array of objects.For that i have taken a constant number as the size of the array.
Now my requirement is that i want to change the number as per the requirement.
Can anybody help me how to change the "number" in number of objects dynamically.That is i want the program to take the number as required for creating the objects.
Thanks in advance
regards
 
Sona Makheeja
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can use a Vector instead of an array,
in for loop or watever, you can say Vector.add();


Hope thsi helps
 
usha mocherla
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sona
but i wanted to know the limit of the for looop which will be running for creating objects.
I think th e solution will work for general dynamically changing values.
I want to deal with "Objects".
Kindly let me know how to do this.
Thnaks in advance
regards
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not entirely clear on what you are looking for, but here are possible answers to your question:

To create a fixed-size array of a length known at compile time:


To create a fixed-size array of a length known at run time:


To populate (any) array:


To create an array of dynamic size -- don't. Use java.util.Lists instead.


The only drawback to Collections (List, Map, Set, etc.) is that they can only hold Objects, not primitives. So, with releases prior to 1.5, you have to manually wrap primitives in their wrappers. Java 1.5 introduces "autoboxing," which will do this for you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!