Results 1 to 2 of 2
  1. #1
    PAffiliates is offline Member
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    JAdmin is offline Member
    Join Date
    Jan 2008
    Posts
    20
    Rep Power
    0

    Default

    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

  1. Tree structure using JAVA
    By trill in forum Advanced Java
    Replies: 2
    Last Post: 05-27-2010, 11:02 AM
  2. Stack data structure in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:34 PM
  3. data structure code
    By vgvt in forum New To Java
    Replies: 1
    Last Post: 01-17-2008, 02:49 PM
  4. Use if then else structure, help
    By paul in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:00 AM
  5. Help with Structure
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •