fork download
  1. import java.util.Map;
  2. import java.util.stream.Collectors;
  3. import java.util.stream.IntStream;
  4.  
  5. class Ideone {
  6. public static void main(String[] args) {
  7. final Integer[] keys = IntStream.range(0, 12).boxed().toArray(Integer[]::new);
  8. final String[] values = new String[] {"Jan", "Feb", "Mar", "Apr", "Mai", "Jun",
  9. "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"};
  10. final Map<Integer, String> map = fillMap(keys, values);
  11. System.out.println(map);
  12. }
  13.  
  14. public static <K, V> Map<K, V> fillMap(K[] keys, V[] values) {
  15. return IntStream.range(0, keys.length)
  16. .boxed()
  17. .collect(Collectors.toMap(
  18. index -> keys[index],
  19. index -> values[index]));
  20. }
  21. }
Success #stdin #stdout 0.08s 48892KB
stdin
Standard input is empty
stdout
{0=Jan, 1=Feb, 2=Mar, 3=Apr, 4=Mai, 5=Jun, 6=Jul, 7=Aug, 8=Sep, 9=Okt, 10=Nov, 11=Dez}