Java Language Collection Factory Methods List Factory Method Examples

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

  • List<Integer> immutableEmptyList = List.of();
    • Initializes an empty, immutable List<Integer>.
  • List<Integer> immutableList = List.of(1, 2, 3, 4, 5);
    • Initializes an immutable List<Integer> with five initial elements.
  • List<Integer> mutableList = new ArrayList<>(immutableList);
    • Initializes a mutable List<Integer> from an immutable List<Integer>.


Got any Java Language Question?