It depends on the type of collection you are creating. I don't think the native java Array types support any functionality like this. However there are other collections that can do these sorts of things, for example Apache Commons Math has a number of structures to do just this sort of thing. Guava is another package with a lot of great Array methods built in.
Another option one could easily implement would be to extend the collection your using. For example:
public class ArrayListExtension extends ArrayList{
public ArrayListExtension(){}
public Double average()
{
Double sum = 0;
Iterator<Double> iterator = this.iterator();
while(iterator.hasNext()){
sum += iterator.next();
}
return sum/this.size();
}
}
Note: There are no sanity checks built into this. In a real-world implementation you'd want to do some try-catch to make sure that the values are actual numbers.