This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array of Structures in java ?" Watch "array of Structures in java ?" New topic
Author

array of Structures in java ?

kri shan
Ranch Hand

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

Joined: Feb 19, 2008
Posts: 2904
    
    1

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
Sheriff

Joined: Oct 13, 2005
Posts: 43970
    
  33
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
Sheriff

Joined: Oct 27, 2005
Posts: 20078
    
  30

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: array of Structures in java ?
 
It's not a secret anymore!