Results 1 to 2 of 2
- 05-15-2011, 06:02 PM #1
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
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!
- 05-15-2011, 06:07 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
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
-
copying contents of an ArrayList to another ArrayList
By ankit1801 in forum New To JavaReplies: 8Last Post: 03-27-2011, 06:07 AM -
sorting arraylist based on another arraylist
By busdude in forum New To JavaReplies: 4Last Post: 02-07-2011, 11:48 AM -
how to add Arraylist filter for a jsp page showing results from a servlet-Arraylist
By alok_sharma in forum Java ServletReplies: 7Last Post: 11-22-2010, 01:26 PM -
A private static ArrayList hold an object and static getter ArrayList
By Louis in forum New To JavaReplies: 2Last Post: 11-16-2010, 05:51 PM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks