File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes array of Structures in java ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array of Structures in java ?" Watch "array of Structures in java ?" New topic

array of Structures in java ?

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1432
How to create array of Structures in java ?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

kri shan wrote:How to create array of Structures in java ?

Are you sure, there is "Structure" in Java?

Or you can define a class, with the attribute you want store in "Structure", something like

and can define array,

and this How "Structure" in C are incorporated into "Classes" in C++
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46429
Beware of drawing analogies from C and C++; lots of people get confused when they go from C/C++ to Java because they think the three languages are the same . . . and they aren't

Yes, as you have already been told, you can have Structure[] arrays, but you cannot have Structure<E>[] arrays, ie arrays of classes with a formal generic type parameter.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Well, you can declare it that way, you just can't create it like that. But with a bit of casting and ignoring / suppressing a warning it is possible to create such an array:

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: array of Structures in java ?
It's not a secret anymore!