Let ArrayList point to another arraylist but with a filter.
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!