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

Thread: Arraylist elements in Treeset

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

    Default Arraylist elements in Treeset

    Hi!

    At the moment I am doing a course for Java Enterprise programmer and I have an asignment I got stuck on.
    I have to create something like a shopping basket. For this I have to put elements from an Arraylist (catalogue with articles) in a Treeset (currently selected articles from the catalogue).
    To be more precise, I have to key in an article number and the program than has to find the related article from the Arraylist and put that in the shopping basket (Treeset).
    Most else is going ok, just this problem, if I can do this I can do the rest of the assignment.
    Hopefully somebody can help me with an example of a similair piece of code.
    Thanx in advance!

    Greets
    Tony


  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: Arraylist elements in Treeset

    find the related article from the Arraylist and put that in the shopping basket (Treeset).
    That sounds like you need a loop to search the arraylist for the element with the key
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Arraylist elements in Treeset

    Thanks! I'll give it a go, but I think it's something wrong with my declaration of the Treeset - private Set<List<Producten>> winkelTs = new TreeSet<List<Producten>>();
    This is a very hard subject I think.

  4. #4
    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: Arraylist elements in Treeset

    If you are getting errors, please copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Looping through ArrayList to remove elements
    By itispj in forum Collections and Generics
    Replies: 3
    Last Post: October 14th, 2011, 12:42 AM
  2. Help with ArrayList ( Adding certain elements together)
    By williamsant in forum Collections and Generics
    Replies: 13
    Last Post: September 27th, 2011, 09:32 AM
  3. [SOLVED] ArrayList object's elements confusing??? doesnt replace the elements? set() method?
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 21st, 2011, 01:20 PM
  4. Duplicate elements in 2 Arraylist
    By tcstcs in forum Collections and Generics
    Replies: 3
    Last Post: April 18th, 2011, 12:56 AM
  5. accessing elements in a 2d ArrayList
    By Flamespewer in forum Collections and Generics
    Replies: 2
    Last Post: March 8th, 2010, 06:11 PM