1

マップから最初の値と 2 番目の値を取得する最良の方法は何ですか? 私は地図を読んでtableLists地図から取得しようとしfirst and second valueています。

ReadTableConnectionInfo以下は、クラスであるコードです。

private final LinkedHashMap<String, ReadTableConnectionInfo> tableLists;

ReadTableConnectionInfo table = tablePicker();


private ReadTableConnectionInfo tablePicker() {

    Random r = new SecureRandom();
    ReadTableConnectionInfo table;

    if (r.nextFloat() < Read.percentageTable / 100) {
        table = get first value from tableLists map
    } else {
        table = get second value from tableLists map
    }

    return table;
}
4

2 に答える 2

1

LinkedHashMap値の反復は、挿入順序順に並べられています。したがって、values()が必要です。

Iterator it = values().iterator();
Object first = it.next().getValue();
Object second = it.next().getValue();
于 2013-02-24T04:03:49.100 に答える