用arraylist映射值

时间:2013-03-18 07:05:48

标签: java arraylist hashmap

if (rs != null) {

    while (rs.next()) {
        rb = new ResponseBean();

        rb.setQuestionOrderNo(rs.getInt(1));

        rb.setResponseLabel(rs.getString(2));

        rb.setTaskName(rs.getString(3));

        rb.setResponder(rs.getString(4));

        rb.setSequenceId(rs.getInt(5));

        checkBoxResponses.add(rb);
    }
}

这个输出是:     RS1 = 10

rs2=Sam

rs3=Manyu

rs4=manyu

rs5=13621

rs1=10

rs2=Sam
--------------------------
rs3=Manyu

rs4=manyu

rs5=13623
------------------------------------
rs1=10

rs2=Sam US
--------------------------------
rs3=Manyu

rs4=manyu

rs5=13623
-------------------------------------------
rs1=10

rs2=Sam India

rs3=Manyu

rs4=manyu

rs5=13624

我想将r5 = 13623的值映射为r2 = Sam,Sam US的值。 请建议我如何继续这样做以获得输出

<13621,Sam>

<13623,(Sam, Sam US)>

<13624, Sam India>

1 个答案:

答案 0 :(得分:1)

您可以使用地图执行此操作: -

HashMap<Integer, List<String>> myMap = new HashMap<Integer, List<String>>(); //Create the Map