020-005-003

Collection Operations: Sorting and Filtering Lists

Hard

Problem Description

Collection Operations

ArrayList supports various operations like sorting and filtering.

Key Methods

ArrayList<Integer> list = new ArrayList<>();
List.add(5);  // Add element
Collections.sort(list);  // Sort ascending
List.removeIf(n -> n % 2 != 0);  // Filter by condition

Learning Points

  • Use Collections.sort() to sort lists
  • Use removeIf() to remove elements not matching condition
  • Use isEmpty() to check if list is empty
.

Test Cases

※ Output examples follow programming industry standards

Input:
5
3
8
1
4
6
Expected Output:
4 6 8
Input:
3
2
2
4
Expected Output:
2 2 4
Input:
3
1
3
5
Expected Output:
No even numbers
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 9 free executions remaining