在arrayList

时间:2018-12-28 20:31:32

标签: java arraylist java-8

嗨,我有一个ArrayList的String ArrayList。示例如下:

  [[765,servus, burdnare],
   [764,asinj, ferrantis],
   [764,asinj, ferrantis],
   [764,asinj, ferrantis],
   [762,asinj, ferrantis],
   [756,peciam terre, cisterne],
   [756,peciam terre, cortile],
   [756,peciam terre, domo],
   [756,asinj, ferrantis]]

是否可以为索引0的每个值在索引1处获得唯一值列表...我期望的结果是:

765 - [servus]
764 - [asinj]
762 - [asinj]
756 - [peciam terre, asinj]

我正在尝试一系列if语句,但是不起作用

3 个答案:

答案 0 :(得分:10)

您可以按index-0元素分组并在getName(): webdriver.promise.Promise<string> { const name = element(by.id("xxxxxx")); return name.getText().catch(e) { return ''; } } 中收集index-1元素以获得唯一性

Set

答案 1 :(得分:1)

可能的变体之一。只需遍历给定列表,并以必需的interface State { translations: { au: 'Hello, mate!', uk: 'Welcome, old chap!' } } interface OwnProps { country: 'au' | 'uk'; } interface ConnectedProps { message: string }; /** * These are all props your component will receive. */ type Props = OwnProps & ConnectedProps; const getMessage = createStructuredSelector<State, OwnProps, ConnectedProps>({ message: (state, props) => state.translations[props.country] }); Map作为值构建key,以忽略重复项。

Set

答案 2 :(得分:0)

鉴于您有List<List<String>>作为来源,可以使用forEach + computeIfAbsent

Map<String, Set<String>> map = new HashMap<>();
list.forEach(l -> map.computeIfAbsent(l.get(0), k -> new HashSet<>()).add(l.get(1)));