English 中文(简体)
j鱼收集问题
原标题:Issue with sorting with collection in java
  • 时间:2010-09-27 23:29:47
  •  标签:
  • java

我的地图是:

HashMap<String,QuoteBean> map = new HashMap<String,QuoteBean>();

http://www.un.org/Depts/DGACM/index_french.htm

class QuoteBean{
    String symbol;
    BigDecimal price;
    BigDecimal quoteprice;
    //setter and getter methods
}

然后,我拿到收集<代码”的地图的数值。 基准/代码

Collection obs  =map.values(); //getting all the quoteobjects
List list = new ArrayList(obs); //converted to list

然后:

Collection.sort(list, new SymbolComparator());

www.un.org/Depts/DGACM/index_spanish.htm 是:

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);
    }    
}

当我执行该守则时,我会收到一种外观,即不能将<代码>String改为QuoteBean,而例外则落在第一行。

问题回答

你们是否积极重新制定关键清单?

Collection obs  =map.values(); //getting all the quoteobjects
List list = new ArrayList(obs);

仅仅是为了确保你能够做些什么。

List<QuoteBean> beans = new ArrayList<QuoteBean>(map.values());

我认为,这两个说法是错误的。

String symbol1=o1.getProductId().getSymbol();
String symbol2=o2.getProductId().getSymbol();

如果你想根据你的话,就只能说 o1。 我仍然不了解什么是用于生产。

我认为,

o1.getProductId().getSymbol();

页: 1

o1.getSymbol();

自古西岛成为财产以来,它就具有象征意义。

class QuoteBean{
    String symbol;
    BigDecimal price;
    BigDecimal quoteprice;
    //setter and getter methods
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签