Q:

Write a method that returns a comma-separated string based on a given list of integers

0

Write a method that returns a comma-separated string based on a given list of integers.

Each element should be preceded by the letter e if the number is even, and preceded by the letter o if the number is odd. For example, if the input list is (3,44), the output should be o3,e44.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public String getString(List<Integer> list) {
return list.stream()
  .map(i -> i % 2 == 0 ? "e" + i : "o" + i)
  .collect(joining(","));
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now