Results 1 to 2 of 2
Thread: Java Array of Structure
- 01-28-2008, 05:28 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 1
- Rep Power
- 0
Java Array of Structure
Greetings! I am new to JAVA. I'm coming over from VB .NET. In VB I was introduced to an array of a structure. It came in handy and I was wondering if it was possible in JAVA. I've tried to find an answer via Google, but can't seem to understand most of the potential examples. My goal is to load several pieces of data of different types into an array and be able to index them all by 1 number per group. So for a simple example I would use firstName, lastName, and age. These would be loaded into the array. I would index them all with the same number. array[0].firstName, array[0].lastname, array[0].age. I'm sorry the syntax is probably incorrect for JAVA, but hopefully you understand what I'm getting at. Any help would be greatly appreciated!!!
Thanks
- 01-28-2008, 06:08 AM #2
Member
- Join Date
- Jan 2008
- Posts
- 20
- Rep Power
- 0
Welcome to Java.
Java has many options to manage information in groups or arrange in orders. Let's take the same example you have given, you need to manage firstName, lastName, and age. So in typical object oriented style, you would create a Person class with these information as attributes. Then each object of this class would represent a person.
Suppose you have many such person objects. Now you need to find a way to manage these objects. In Java, the collection framework does the trick for you.
Java collection is a framework with a group of classes and interfaces that help in manipulating objects as a single unit. Collection classes are commonly used Java and belong to the java.util package. For more details on Collections, go to Trail: Collections (The Java™ Tutorials). You may also look at 'Arrays' in java (Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics))
Ok, lets get back to your specific need. If you want to have an ordered list of information - such as person objects-, you may use an ArrayList. ArrayList is ordered and allows positional access (acess information using index) .
(Note :ArrayList is the concrete implementation of the List interface)
We know this is a lot of stuff but once you get an idea of the Collection framework, you will apprecite its usefulness in Java.
Do not hesitate to ask questions, if you come across anything that needs little more explanation.
Hope this helps!Sincerely, Your friends at www.javaadvice.com
Similar Threads
-
Tree structure using JAVA
By trill in forum Advanced JavaReplies: 2Last Post: 05-27-2010, 11:02 AM -
Stack data structure in Java
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:34 PM -
data structure code
By vgvt in forum New To JavaReplies: 1Last Post: 01-17-2008, 02:49 PM -
Use if then else structure, help
By paul in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:00 AM -
Help with Structure
By Albert in forum New To JavaReplies: 1Last Post: 07-13-2007, 03:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks