Results 1 to 2 of 2
  1. #1
    gonzalioz is offline Member
    Join Date
    May 2011
    Rep Power

    Default Let ArrayList point to another arraylist but with a filter.

    Hi all,

    I have a ArrayList called messages in a class called Database.

    ArrayList<Message> messages = new ArrayList<Message>();

    In this arraylist are all the records of the database table called messages...

    I also have a User object. In this user object I also have a list with messages. But I want to point this list to the big one but only the messages that belong to this user. However when I would add something to this list: for example: UserA.getMessages().Add(something) I want it to be added to the big one. But when I am looping through it. For example: for (Message m : UserA.getMessages()) I want it to look in the big one, but only find messages that belong to this user.

    I know, it's pretty confusing. I hope you guys understand and can help me. Basically what I am looking for is some kind of filter that I can put over the user copy of the big list that will only show the messages that belong to that user but when I add something, it will be added to the big list.

    Thanks in advance for your help!

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Rep Power


    If I understand what you want correctly, it seems a Map might work well for you - keyed with the User and valued with the list of messages associated with that user:
    The Map Interface (The Java™ Tutorials > Collections > Interfaces)

Similar Threads

  1. copying contents of an ArrayList to another ArrayList
    By ankit1801 in forum New To Java
    Replies: 8
    Last Post: 03-27-2011, 07:07 AM
  2. sorting arraylist based on another arraylist
    By busdude in forum New To Java
    Replies: 4
    Last Post: 02-07-2011, 12:48 PM
  3. Replies: 7
    Last Post: 11-22-2010, 02:26 PM
  4. Replies: 2
    Last Post: 11-16-2010, 06:51 PM
  5. Replies: 2
    Last Post: 04-21-2008, 12:43 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