I have a hashmap:
HashMap<String,QuoteBean> map = new HashMap<String,QuoteBean>();
The QuoteBean is a normal bean:
class QuoteBean{
String symbol;
BigDecimal price;
BigDecimal quoteprice;
//setter and getter methods
}
Then, I get the values of the map which a collection of QuoteBean objects
Collection obs =map.values(); //getting all the quoteobjects
List list = new ArrayList(obs); //converted to list
Then to sort:
Collection.sort(list, new SymbolComparator());
SymolComparator is:
public class SymbolComparator implements Comparator<QuoteBean>{
String symbol;
@Override
public int compare(QuoteBean o1, QuoteBean o2) {
String symbol1=o1.getProductId().getSymbol();
String symbol2=o2.getProductId().getSymbol();
return symbol1.compareTo(symbol2);
}
}
When I execute the code I get an exeception which says cannot convert String to QuoteBean and the exception throws on the first line.