import com.mindprod.accumulate; ... Accumulate buckets = new Accumulate( 20 /* estimated categories */ ); buckets.accumulate( "ugli fruit", 3 ); buckets.accumulate( "peaches", 10 ); buckets.accumulate( "strawberries", 15 ); buckets.accumulate( "peaches", 14 ); String[] categories = buckets.categories(); // prints totals sorted in alphabetical order: // peaches:24 // strawberries:15 // ugli fruit:3 for ( int i=0; i<categories.length; i++ ) { out.println( categories[i] + ":" + buckets.total( categories[i] )); }