159k views
5 votes
Write a method called listUpper() that takes in a list of strings, and returns a list of the same length containing the same strings but in all uppercase form. You can either modify the provided list or create a new one.

1 Answer

3 votes

Answer:

public static List<String> listUpper(List<String> list){

List<String> upperList = new ArrayList<String>();

for(String s:list){

s = s.toUpperCase();

upperList.add(s);

}

return upperList;

}

Step-by-step explanation:

Create a method named listUpper that takes list as a parameter

Inside the method, initialize a new list named upperList. Create a for-each loop that iterates through the list. Inside the loop, convert each string to uppercase, using toUpperCase method, and add it to the upperList.

When the loop is done, return the upperList

User Tholle
by
4.5k points