I need to create 3 lists based on these three objects:
{"cat","owl","fish","mouse","elephant"}
{"cat","owl","fish","mouse","elephant"}
{"cat","owl","fish","mouse","elephant"}
How do I save space so that I don't specify"mouse", "elephant" 3 times? The objects are iterated through and I don't know in advance what the object contains.
// pseudocode
public static List<String> getValuesAsList(myCoolObjects)
    for(MyCoolObject myCoolObject: MyCoolObjects){
    List<String> listContainingObjectValues = new ArrayList<>();
       listContainingObjectvalues.add(myCoolObject.getValue1());
       listContainingObjectvalues.add(myCoolObject.getValue2());
       listContainingObjectvalues.add(myCoolObject.getValue3());
    }
    return listContaingObjectValues;
So that the result would not be like this:
List 1 ["cat","mouse","elephant"]
List 2 ["owl","mouse","elephant"]
List 3 ["fish","mouse","elephant"]
The desired result would be this:
List 1 ["cat","mouse","elephant"]
List 2 ["owl",*points to 'List 1.[1]', *points to 'List 1.[2]'*]
List 3 ["fish",*points to 'List 1.[1]', *points to 'List 1.[2]'*]
Is this something that Java already does?
 
    