fork download
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.Map;
  4. import java.util.stream.Collectors;
  5. import java.util.stream.IntStream;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. List<Integer> list = Arrays.asList(1, 2, 2, 1, 4, 5, 4, 3, 4, 5, 0);
  10. final Map<Integer, List<Integer>> indexMap = IntStream.range(0, list.size()).boxed()
  11. .collect(Collectors.groupingBy(list::get));
  12. System.out.println(indexMap);
  13. }
  14. }
Success #stdin #stdout 0.13s 34304KB
stdin
Standard input is empty
stdout
{0=[10], 1=[0, 3], 2=[1, 2], 3=[7], 4=[4, 6, 8], 5=[5, 9]}