如何在 Hashmap 中读取具有开始和结束限制的键的值?

How to read values of a key with start and end limit in Hashmap?

我有 HashMap 测试图;

这是用这种方式拥有多个键的数据,

{
    status = [1, 2, 3, 4, 5], data = [
        [1, 2, 3, 4, 5, 6],
        [7, 8 9, 10, 11, 12],
        [13, 14 15, 16, 17, 18],
        [19, 20, 21, 22, 23, 24],
        [25, 26, 27, 28, 29, 30],
    ]
], warning = [
    [1, 2, 3, 4, 5, 6],
    [7, 8 9, 10, 11, 12],
    [13, 14 15, 16, 17, 18],
    [19, 20, 21, 22, 23, 24],
    [25, 26, 27, 28, 29, 30],
], error = [1, 2, 3, 4, 5, 6], [7, 8 9, 10, 11, 12], [13, 14 15, 16, 17, 18], [19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30],
}

我正在尝试从上面的地图 LIMIT 中读取每个键的值。

即,最初开始 limit =1 结束 limit-3,那么应该从上述 hashmap 的每个键中只获得 1,2,3 个值。

然后,如果我发送开始限制 =4 和结束限制-6,那么应该只从上述哈希映射的每个键中获取 4、5、6 个值。

我试过这种方式,

Object firstKey = myHashMap.keySet().toArray()[3];
Object valueForFirstKey = myHashMap.get(firstKey);
//iterated the values from so getting 

这样, [数据 = [1,2,3]]

     Instead of this looping , can i get subset of values using both start and end index from hashmap for all the above keys like this?
if start index=1 and end index =3 it should return me output this way,

{
    status = [1, 2, 3], data = [
        [1, 2, 3],
        [7, 8 9],
        [13, 14 15],
        [19, 20, 21],
        [25, 26, 27],
    ]
], warning = [
    [1, 2, 3, [7, 8 9],
        [13, 14 15],
        [19, 20, 21],
        [25, 26, 27],
    ], error = [1, 2, 3],
    [7, 8 9],
    [13, 14 15],
    [19, 20, 21],
    [25, 26, 27],
}

没有像上面那样遍历每个键和值?我犯了什么错误?

就像 Jon Skeet 指出的那样,不清楚你在问什么。

我猜你最需要的是:

item.data
  .SelectMany(o => o)   // linarilize array of arrays
  .Skip(i * 3)          // skip first i * 3 elements 
  .Take(3);             // take first 3 elements from remaining array

此示例是在 c# 中,在 Java 中您有更详细的方法。如果您碰巧使用 Java 8 那么我想您可以通过以下方式解决此问题:

integerListStream
  .flatMap(Collection::stream)
  .skip(i * 3)
  .limit(3);