The longest string in the list

Report a typo

Implement the changeList method so that it:

  1. finds the longest string in the list
  2. replaces all list items with the found string

Sample Input 1:

hi hello goodmorning

Sample Output 1:

goodmorning goodmorning goodmorning
Write a program in Java 17
import java.util.*;

public class Main {

static void changeList(List<String> list) {
// write your code here
}

/* Do not change code below */
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
List<String> lst = Arrays.asList(s.split(" "));
changeList(lst);
lst.forEach(e -> System.out.print(e + " "));
}
}
___

Create a free account to access the full topic