import com.github.andrewoma.dexx.collection.List; public class ImmutableArrayListExample { public static void main(String[] args) { List<String> immutableList = List.of("apple", "banana", "orange"); } } import com.github.andrewoma.dexx.collection.Set; public class ImmutableHashSetExample { public static void main(String[] args) { Set<String> immutableSet = Set.of("apple", "banana", "orange"); } } import com.github.andrewoma.dexx.collection.Map; public class ImmutableHashMapExample { public static void main(String[] args) { Map<String, Integer> immutableMap = Map.of("apple", 1, "banana", 2, "orange", 3); } } import com.github.andrewoma.dexx.collection.List; public class CollectionOperationsExample { public static void main(String[] args) { List<Integer> numbers = List.of(1, 2, 3, 4, 5); List<Integer> filteredNumbers = numbers.filter(n -> n > 2); System.out.println("Filtered numbers: " + filteredNumbers); List<Integer> squaredNumbers = numbers.map(n -> n * n); System.out.println("Squared numbers: " + squaredNumbers); int sum = numbers.reduce(0, (a, b) -> a + b); System.out.println("Sum: " + sum); } }


上一篇:
下一篇:
切换中文