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 2 of 2

Thread: Joining two different generic type of ArrayList.

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    5
    My Mood
    Angelic
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Joining two different generic type of ArrayList.

    Hi!There is a question! I want to combine:
    List<String> string=new ArrayList<String>(); and List<Integer> numbers=new ArrayList<Integer>();

    And the new ArrayList should have both elements in one index as :
    index[0]--->(string.get(0),numbers.get(o))--->("Many many thanks for your help",6)
    So, then I could sort by numbers it would have.



    I tried to use Hashtable but as its key unique,it doesn't work for me. Is it possible to merge in this way? Or not?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Joining two different generic type of ArrayList.

    Sounds like you need to have a custom class that holds a String and number and some methods for accessing it contents and sorting. Instances of that class could be put in an ArrayList<YourCustomClass>
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Aika (October 30th, 2013)

Similar Threads

  1. [SOLVED] Which is better Vector<type> or ArrayList ?
    By Andrew R in forum Java Theory & Questions
    Replies: 9
    Last Post: August 14th, 2013, 01:00 PM
  2. Replies: 2
    Last Post: August 4th, 2013, 08:57 PM
  3. How to convert an array of integer to generic type?
    By colerelm in forum Object Oriented Programming
    Replies: 2
    Last Post: October 20th, 2012, 04:08 AM
  4. having problem declaring a generic type array in OrderSet class
    By mia_tech in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 10th, 2012, 06:39 PM
  5. Creating array from generic type objects?
    By AndrewMiller in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 13th, 2010, 09:22 PM