Functional-1

doubling

public List<Integer> doubling(List<Integer> nums) {
  List<Integer> answer = new ArrayList<>();
  answer = nums.stream()
    .map(n -> n*2)
    .collect(Collectors.toList());
  return answer;
}
public List<Integer> doubling(List<Integer> nums) {
  nums.replaceAll(n -> n * 2);
  return nums;
}

square

public List<Integer> square(List<Integer> nums) {
  nums.replaceAll(n -> n * n);
  return nums;
}

addStar

public List<String> addStar(List<String> strings) {
  strings = strings.stream()
    .map(n -> n+"*")
    .collect(Collectors.toList());
  return strings;
}

copies3

public List<String> copies3(List<String> strings) {
  strings = strings.stream()
    .map(n -> n + n + n)
    .collect(Collectors.toList());
  return strings;
}

moreY

public List<String> moreY(List<String> strings) {
  strings = strings.stream()
    .map(n -> "y"+n+"y")
    .collect(Collectors.toList());
  return strings;
}

math1

public List<Integer> math1(List<Integer> nums) {
  nums = nums.stream()
    .map(n -> (n+1)*10)
    .collect(Collectors.toList());
  return nums;
}

rightDigit

public List<Integer> rightDigit(List<Integer> nums) {
  nums = nums.stream()
    .map(n -> n%10)
    .collect(Collectors.toList());
  return nums;
}

Ref

lower

public List<String> lower(List<String> strings) {
  return strings.stream()
    .map(s -> s.toLowerCase())
    .collect(Collectors.toList());
    
}

Ref

noX

  • .map(s -> s.replaceAll("x",""))

public List<String> noX(List<String> strings) {
  return strings.stream()
    .map(s -> s.replaceAll("x",""))
    .collect(Collectors.toList());
}

Ref

Last updated