Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Array type of structure with different types in different columns

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array type of structure with different types in different columns

    Is there a structure wherein I can have strings in col1, doubles in col2, integers in col3?


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,659
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: Array type of structure with different types in different columns

    Theoretically, a 2d array, but that would be messy. I would suggest making each "row" an object, which has values for col1, col2, and col3, and then putting the rows in an array. That would be the cleanest solution.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,073
    My Mood
    Mellow
    Thanks
    184
    Thanked 652 Times in 639 Posts

    Default Re: Array type of structure with different types in different columns

    Rather than using parallel arrays to store data, use a CLASS. A class might be structured something like:
    public class MyDataStructure
    {
        // instance variables
        String columnOne;
        double columnTwo;
        int columnThree;
     
        // a constructor that sets each instance variable
        public MyDataStructure( String columnOne, double columnTwo, int columnThree )
        {
            this.columnOne = columnOne;
            this.columnTwo = columnTwo;
            this.columnThree = columnThree;
     
        } // end constructor
     
    } // end class MyDataStructure

Similar Threads

  1. Replies: 4
    Last Post: February 22nd, 2013, 02:51 PM
  2. types in a multidimensional array
    By hannah87 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 22nd, 2013, 07:23 AM
  3. Replies: 2
    Last Post: January 14th, 2013, 02:22 PM
  4. Exception in main thread for 2D Array (columns)
    By java_begginer in forum Exceptions
    Replies: 2
    Last Post: December 3rd, 2012, 03:44 PM
  5. Search for min and max values as columns position in array
    By susieferrari in forum Java Theory & Questions
    Replies: 3
    Last Post: April 28th, 2011, 07:39 AM