Skip to content

Commit 8563ce8

Browse files
committed
Day-6 : Group the strings based on the middle character
1 parent 6d85be0 commit 8563ce8

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.java8;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.stream.Collectors;
7+
8+
public class CheckDistinctValuesInArray {
9+
public static void main(String[] args) {
10+
int[] arr = {1, 2, 0, 5, 7, 9, 0};
11+
List<Integer> integerList = Arrays.stream(arr).boxed().toList();
12+
Map<Integer, Long> countMap = integerList.stream().collect(Collectors.groupingBy(x -> x, Collectors.counting()));
13+
boolean distinctChecker = countMap.values().stream().noneMatch(x -> x > 1);
14+
System.out.println("Given array contains distinct elements: " + distinctChecker);
15+
}
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.java8;
2+
3+
import java.util.stream.Collectors;
4+
import java.util.stream.Stream;
5+
6+
public class GroupStrings {
7+
public static void main(String[] args) {
8+
String[] strList = {"ewe", "aha", "jji", "kwk", "jhj"};
9+
System.out.print(Stream.of(strList).collect(Collectors.groupingBy(x -> x.substring(1, 2))));
10+
}
11+
}

0 commit comments

Comments
 (0)