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: How to store differingdata types and which data structure is best to store them

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to store differingdata types and which data structure is best to store them

    Hi there,

    This is my first post so please forgive me and try to guide me if I have posted in the wrong area.

    My question is, given that in core java, with no access to libraries or collections what would be the best approach to storing product data i.e. a mixture of types meaning String data Boolean data and Integer or double data and what data structure would be the most suitable to store the aforementioned data as data objects.

    For instance, say I want to create and store the following as an object, integer productId, String productName, boolean inStock. How to create the object and then what data structure is best for storing these objects? I would need to add, delete, insert new objects as well.

    I would also need to sort the data in some sort of order perhaps by productId or by inStock so another question is what is the approach considering that the data fields are in an object.

    Is it possible to write a method to sort the data that is stored in an object of differing types.

    Regards,

    Ironoverload (feToHigh)

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,193
    Thanks
    53
    Thanked 2,626 Times in 2,576 Posts

    Default Re: How to store differingdata types and which data structure is best to store them

    To save a number of related data items, create a class to hold all those items in its fields. If the program is not allowed to use any of the collection classes, then it could use a self defined linked list or a large array. If the contents of the list of objects needs to be changed, you would have to write methods to do that.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to store differingdata types and which data structure is best to store them

    Thank you very much for the approach to my question I appreciate it.

Similar Threads

  1. data structure to store objects with different number of parameters
    By Ameer in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 7th, 2020, 12:18 AM
  2. [SOLVED] How do I save organized data and store it locally?
    By angstrem in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: March 15th, 2013, 11:57 AM
  3. how to get a data from database and store it in a variable?
    By jabaman in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 6th, 2012, 03:34 PM
  4. Replies: 3
    Last Post: November 8th, 2012, 01:24 PM
  5. array to store multiple names and data
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 2
    Last Post: May 6th, 2011, 05:03 AM

Tags for this Thread