Question: I need to have a `UserProfile` class that it's just that, a user profile. This user profile has some vital user data of course, but it also needs to have lists of messages sent from the user friends.

I need to save these messages in `LinkedList`, `ArrayList`, `HashMap` and `TreeMap`. But only one at a time and not duplicate the message for each data structure. Basically, something like a dynamic variable type where I could pick the data type for the messages.

Is this, somehow, possible in Java? Or my best approach is something [like this](https://stackoverflow.com/questions/2881684/help-with-abstract-class-in-java-with-private-variable-of-type-liste)? I mean, have 2 different classes (for the user profile), one where I host the messages as `Map<K,V>` (and then I use `HashMap` and `TreeMap` where appropriately) and another class where I host them as `List<E>` (and then I use `LinkedList` and `ArrayList` where appropriately). And probably use a super class for the `UserProfile` so I don't have to duplicate variables and methods for fields like data, age, address, etc...

Any thoughts?

Answer: 
I ended up using what I described on the first post:

> 
> Is this, somehow, possible in Java? Or
>  my best approach is something like
>  this? I mean, have 2 different classes
>  (for the user profile), one where I
>  host the messages as Map (and
>  then I use HashMap and TreeMap where
>  appropriately) and another class where
>  I host them as List (and then I use
>  LinkedList and ArrayList where
>  appropriately). And probably use a
>  super class for the UserProfile so I
>  don't have to duplicate variables and
>  methods for fields like data, age,
>  address, etc...
> 
> 
>
If this is a university project, then I suspect that what you are meant to do is this:

```
Collection mycoll;
mycoll = new ArrayList();
for (Message m:message) {
  // do stuff and measure the performance
}
// do other stuff and measure the performance
mycoll = new LinkedList();
// do the same stuff as a above and measure the performance again
mycoll = new HashMap();
//... and so on

```

As stated above, adding an object to a collection doesn't duplicate it.