我在HashMap<Integer,Product>
產品對象的名單我想做的排序
ProductName ProductCode Qty Price
Pen 100011 10 10.00 product1
Penci 100012 5 5.00 product2
HashMap<Integer,Product> productMap = new HashMap<Integer,Product>();
當用戶點擊在ProductName,productCode或Price上,對象應根據我的要求進行排序。
I added like this.
productMap .put(1,product1);
productMap .put(2,product2);
我怎麼能幹這事要使用object.not關鍵
請幫我整理。
在此先感謝
http://stackoverflow.com/questions/1206073/sorting-a-collection-of-objects – sathis
HashMap是無序的。可以先獲得['entrySet'](http://download.oracle.com/javase/6/docs/api/java/util/Map.html#entrySet%28%29),然後對其進行排序...然而,也許看到[這是關於「有序地圖」的SO問題](http://stackoverflow.com/questions/663374/java-ordered-map)。 – 2011-11-08 05:47:48