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

array of Structures in java ?

 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to create array of Structures in java ?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic