开发者

How to declare cluster in java?

I need to create clusters that contain elements. The clusters should be created at run-time and elements to be added to it. How do I do it 开发者_开发百科in Java?

I thought of declaring a class as a cluster, but then I cant declare objects dynamically and iterate over them.


You really haven't explained what a cluster is, but you can add "elements" to a List. Or indeed anything else in the Collections library. Instantiate when you feel like it:

List<YourObject> cluster = new ArrayList<YourObject>();  

and add additional elements when you want, the list will grow automatically:

cluster.add(yourObject);

You can also iterate over a list.


I'm not sure I quite understand the question, but you might want to look at the Collections framework.

http://download.oracle.com/javase/tutorial/collections/index.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜