{"id":18816162,"url":"https://github.com/ljacqu/javacollectionbehavior","last_synced_at":"2026-01-14T08:30:16.195Z","repository":{"id":71344973,"uuid":"307121540","full_name":"ljacqu/JavaCollectionBehavior","owner":"ljacqu","description":"Test cases to document different Java collections and their differences","archived":false,"fork":false,"pushed_at":"2024-05-19T11:15:51.000Z","size":130,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-19T14:01:43.948Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ljacqu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-25T14:50:32.000Z","updated_at":"2024-06-03T18:35:04.133Z","dependencies_parsed_at":"2023-09-26T16:33:23.694Z","dependency_job_id":"1345f2a7-e10f-4783-a348-aa6a3766df1d","html_url":"https://github.com/ljacqu/JavaCollectionBehavior","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljacqu%2FJavaCollectionBehavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljacqu%2FJavaCollectionBehavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljacqu%2FJavaCollectionBehavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljacqu%2FJavaCollectionBehavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ljacqu","download_url":"https://codeload.github.com/ljacqu/JavaCollectionBehavior/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239753703,"owners_count":19691160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T23:52:40.024Z","updated_at":"2026-01-14T08:30:16.148Z","avatar_url":"https://github.com/ljacqu.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Java collection behavior\n\nShowcases the behavior of various `List`, `Set` and `Map` implementations and their\ndifferences.\n\nSome highlights are given in this readme. Refer to the unit tests for all the details.\n\n## Difference between Collectors#toList, Collectors#toUnmodifiableList and Stream#toList\nConsider the following blocks:\n```java\nList\u003cInteger\u003e list1 = Stream.of(1, 2, 3)\n  .collect(Collectors.toList()); // Since Java 8\nList\u003cInteger\u003e list2 = Stream.of(1, 2, 3)\n  .collect(Collectors.toUnmodifiableList()); // Since Java 10\nList\u003cInteger\u003e list3 = Stream.of(1, 2, 3)\n  .toList(); // Since Java 16\n```\n\nIs there any difference?\n- **Collectors#toList** currently returns an ArrayList, but the Javadoc actually does not guarantee what implementation is\n  returned—not even if the list can be modified further! Prefer the more verbose \n  `Collectors.toCollection(ArrayList::new)` if you need to make more changes to a List created by a Stream.\n- **Collectors#toUnmodifiableList** does not support nulls. Also in read-only methods like `list2.contains(null)`, an\n  exception will be thrown by the list.\n- **Stream#toList** supports nulls, and calling something like `list3.contains(null)` is fine.\n\n## Difference between Collections#unmodifiableSet, Set#copyOf and Guava's ImmutableSet#copyOf\n```java\nSet\u003cInteger\u003e origin = new LinkedHashSet\u003c\u003e(Arrays.asList(1, 2, 3));\n\nSet\u003cInteger\u003e set1 = Collections.unmodifiableSet(origin);\nSet\u003cInteger\u003e set2 = Set.copyOf(origin);\nSet\u003cInteger\u003e set3 = ImmutableSet.copyOf(origin);\n```\n\n- Set#copyOf and Guava's ImmutableSet#copyOf make a copy of the original collection, so they produce _immutable_\n  collections: if `origin` is changed afterwards, `set2` and `set3` will not change. Collections#unmodifiableSet\n  produces a set that delegates to the origin; `set1` cannot be modified directly but any changes to `origin` are\n  still reflected. It is _unmodifiable_  but not _immutable_.\n- Set#copyOf and ImmutableSet#copyOf throw an exception if any entry is null.\n- The methods on Set#copyOf throw an exception if null is supplied to them (also, for instance, for\n  `set2.contains(null)`).\n- Collections#unmodifiableSet and ImmutableSet#copyOf keep the order of the original collection; Set#copyOf does not.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljacqu%2Fjavacollectionbehavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fljacqu%2Fjavacollectionbehavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljacqu%2Fjavacollectionbehavior/lists"}