1

I'm new in Java but have some experience in Delphi and Object pascal.

I want to define a array of a record like as below example:

TMyItems = record
   Items: TItems; 
   count: integer;
end;

PlayerItems : array of TMyItems;

How can I make it in Java and fetch the items from it?

I just need to define an array for items and its count. how I can do it in Java?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
SadeghAlavizadeh
  • 609
  • 3
  • 17
  • 33
  • 7
    Don't try and think about converting Delphi/Pascal to Java. Learn how arrays work in Java and use them. – Sotirios Delimanolis Mar 31 '14 at 16:03
  • I wont to convert I just need define an array for put an object and its count to it – SadeghAlavizadeh Mar 31 '14 at 16:07
  • 1
    Every text book on Java covers arrays. Don't learn a new language by asking questions on SO for every single language feature. – David Heffernan Mar 31 '14 at 16:12
  • 2
    In addition to what others have said, I believe any answer to this would be too lengthy, and would only repeat what can very easily be found in text books, tutorials, or even other [questions on SO](http://stackoverflow.com/q/5364278/877472). Plus, the answer would ultimately do too much work for you, and rob you of the opportunity to learn this fundamental-java concept concretely yourself. I would search about classes and arrays in java, and go from there (the [official java tutorials](http://docs.oracle.com/javase/tutorial/java/index.html) might be a good place to start). – Paul Richter Mar 31 '14 at 16:43

1 Answers1

0

In Java, lists are more useful and usually more idiomatic than arrays. Arrays are low-level and a bit clunky.

Java doesn't have records or structs. You'd create a class instead of defining a record.

One of the first things you should check out after learning the language basics is the java.util package, which is where you have useful stuff like lists and maps and sets created for you. A good class to start with is java.util.ArrayList. You can create a list with a generic type parameter that specifies what goes in it.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276