I have a list of objects, for example
List<Document> myList = new ArrayList<Document>();
myList.add(new Document("TypeA"));
myList.add(new Document("TypeB"));
myList.add(new Document("TypeA"));
myList.add(new Document("TypeA"));
myList.add(new Document("TypeB"));
Now every Document has a different type property, which is what I pass to the constructor (It's not the real case, just trying to simplify it.
What I need to do is, add a new property "counter" to all of the Document objects, with the same Type. So the three Document objects with "TypeA" need to have incrementing counter values (1,2,3). If there is only one Document with a specific type, then it shouldn't have a counter value.
So I guess I basically need to somehow filter (group) them and then iterate them. But how can I do this efficiently?
I have JavaScript background, and there it would be easy for me, but with Java all I found, seems to be complicated.