Java-合并重复键并从映射中删除重复值

时间:2018-10-31 11:06:49

标签: java collections

我有包含重复值的地图。像这样:

import string
import pygame as pg


pg.init()
screen = pg.display.set_mode((640, 480))
clock = pg.time.Clock()
BG_COLOR = pg.Color('gray12')
CHARACTERS = set(string.ascii_letters+string.digits+string.punctuation)
print(CHARACTERS)
words = []

done = False
while not done:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            done = True
        elif event.type == pg.KEYDOWN:
            if event.unicode in CHARACTERS:
                words.append(event.unicode)
                print(''.join(words))

    screen.fill(BG_COLOR)
    pg.display.flip()
    clock.tick(60)

pg.quit()

我想合并相同组名键的值,然后从值名键中删除重复的值。 因此最终地图将如下所示:

{
"GROUP-A": {
    "groupname": "name1",
    "valuename": [
        "value1",
        "value2"
    ]
},
"GROUP-B": {
    "groupname": "name2",
    "valuename": [
        "value1",
        "value2"
    ]
},
"GROUP-C": {
    "groupname": "name2",
    "valuename": [
        "value2",
        "value3"
    ]
}
}

为组名和值名字段创建了Bean。

我有一个映射,该映射返回String(例如GROUP-A)作为键,并且bean返回值。

0 个答案:

没有答案