{"id":402,"date":"2023-10-25T14:27:45","date_gmt":"2023-10-21T05:48:05","guid":{"rendered":"https:\/\/www.silicloud.com\/ja\/blog\/index.php\/2023\/11\/30\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/"},"modified":"2025-07-31T23:18:48","modified_gmt":"2025-07-31T14:18:48","slug":"java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/","title":{"rendered":"Java\u306eSet\u306f\u3001Java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002"},"content":{"rendered":"<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/65648bf0daa94e2bdf7bc351\/0-0.png\" alt=\"\" \/><\/div>\n<h3>Java Set (\u30b8\u30e3\u30f4\u30a1\u30fb\u30bb\u30c3\u30c8)<\/h3>\n<p>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001Java\u306eSet\u306b\u3064\u3044\u3066\u306e\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u306b\u3064\u3044\u3066\u8b70\u8ad6\u3057\u307e\u3059\u3002<\/p>\n<ul class=\"post-ul\">\n<li>Java Set interface is a member of the Java Collections Framework.<\/li>\n<li>Unlike List, Set DOES NOT allow you to add duplicate elements.<\/li>\n<li>Set allows you to add at most one null element only.<\/li>\n<li>Set interface got one default method in Java 8: spliterator.<\/li>\n<li>Unlike List and arrays, Set does NOT support indexes or positions of it\u2019s elements.<\/li>\n<li>Set supports Generics and we should use it whenever possible. Using Generics with Set will avoid ClassCastException at runtime.<\/li>\n<li>We can use Set interface implementations to maintain unique elements.<\/li>\n<\/ul>\n<h3>Java\u306eSet\u30af\u30e9\u30b9\u306e\u56f3\u89e3<\/h3>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/65648bf0daa94e2bdf7bc351\/5-0.jpg\" alt=\"\" \/><\/div>\n<h3>Java\u306e\u30bb\u30c3\u30c8\u30e1\u30bd\u30c3\u30c9\u3092\u8ff0\u3079\u308b\u3002<\/h3>\n<p>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3044\u304f\u3064\u304b\u306e\u4fbf\u5229\u306aJava Set\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u8a71\u3057\u5408\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4ee5\u4e0b\u306f\u3001\u30cd\u30a4\u30c6\u30a3\u30d6\u306e\u65e5\u672c\u8a9e\u3067\u306e\u4e00\u3064\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>int size(): Set\u5185\u306e\u8981\u7d20\u6570\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<br \/>\nboolean isEmpty(): Set\u304c\u7a7a\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002<br \/>\nboolean contains(Object o): \u6307\u5b9a\u3055\u308c\u305f\u8981\u7d20\u304c\u3053\u306eSet\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u5834\u5408\u306btrue\u3092\u8fd4\u3057\u307e\u3059\u3002<br \/>\nIterator iterator(): \u3053\u306e\u30bb\u30c3\u30c8\u306e\u8981\u7d20\u4e0a\u306b\u53cd\u5fa9\u5b50\u3092\u8fd4\u3057\u307e\u3059\u3002\u8981\u7d20\u306f\u7279\u5b9a\u306e\u9806\u5e8f\u3067\u306f\u8fd4\u3055\u308c\u307e\u305b\u3093\u3002<br \/>\nObject[] toArray(): \u3053\u306e\u30bb\u30c3\u30c8\u306e\u3059\u3079\u3066\u306e\u8981\u7d20\u3092\u542b\u3080\u914d\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002\u3053\u306e\u30bb\u30c3\u30c8\u304c\u8981\u7d20\u3092\u8fd4\u3059\u9806\u5e8f\u306b\u3064\u3044\u3066\u4fdd\u8a3c\u304c\u3042\u308b\u5834\u5408\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u540c\u3058\u9806\u5e8f\u3067\u8981\u7d20\u3092\u8fd4\u3055\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<br \/>\nboolean add(E e): \u6307\u5b9a\u3055\u308c\u305f\u8981\u7d20\u3092\u3053\u306e\u30bb\u30c3\u30c8\u306b\u8ffd\u52a0\u3057\u307e\u3059\uff08\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u64cd\u4f5c\uff09\u3002<br \/>\nboolean remove(Object o): \u6307\u5b9a\u3055\u308c\u305f\u8981\u7d20\u3092\u3053\u306e\u30bb\u30c3\u30c8\u304b\u3089\u524a\u9664\u3057\u307e\u3059\uff08\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u64cd\u4f5c\uff09\u3002<br \/>\nboolean removeAll(Collection c): \u6307\u5b9a\u3055\u308c\u305f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u3053\u306e\u30bb\u30c3\u30c8\u306e\u8981\u7d20\u3092\u3059\u3079\u3066\u524a\u9664\u3057\u307e\u3059\uff08\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u64cd\u4f5c\uff09\u3002<br \/>\nboolean retainAll(Collection c): \u3053\u306e\u30bb\u30c3\u30c8\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u6307\u5b9a\u3055\u308c\u305f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306e\u8981\u7d20\u306e\u307f\u3092\u4fdd\u6301\u3057\u307e\u3059\uff08\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u64cd\u4f5c\uff09\u3002<br \/>\nvoid clear(): \u30bb\u30c3\u30c8\u304b\u3089\u3059\u3079\u3066\u306e\u8981\u7d20\u3092\u524a\u9664\u3057\u307e\u3059\u3002<br \/>\nIterator iterator(): \u3053\u306e\u30bb\u30c3\u30c8\u306e\u8981\u7d20\u306b\u5bfe\u3059\u308b\u53cd\u5fa9\u5b50\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<h3>Java\u306e\u914d\u5217\u3092\u30bb\u30c3\u30c8\u306b\u5909\u63db\u3059\u308b<\/h3>\n<p>List\u3068\u306f\u7570\u306a\u308a\u3001Java\u306eSet\u306f\u76f4\u63a5\u914d\u5217\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u306a\u305c\u306a\u3089\u3001Set\u306f\u914d\u5217\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044\u304b\u3089\u3067\u3059\u3002\u305d\u306e\u305f\u3081\u3001Arrays\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3066\u914d\u5217\u306e\u30d3\u30e5\u30fc\u3092\u30bb\u30c3\u30c8\u3068\u3057\u3066\u53d6\u5f97\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u5225\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u3092\u53d6\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002Arrays.asList()\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u914d\u5217\u3092\u30ea\u30b9\u30c8\u306b\u5909\u63db\u3057\u3001\u305d\u308c\u3092\u4f7f\u7528\u3057\u3066\u30bb\u30c3\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u65b9\u6cd5\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001Java\u306e\u914d\u5217\u3092\u30bb\u30c3\u30c8\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u30022\u3064\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u305d\u308c\u305e\u308c1\u3064\u305a\u3064\u7c21\u5358\u306a\u4f8b\u3092\u4f7f\u3063\u3066\u8aac\u660e\u3057\u307e\u3059\u3002\u30a2\u30d7\u30ed\u30fc\u30c11\u3067\u306f\u3001\u6700\u521d\u306b\u4e0e\u3048\u3089\u308c\u305f\u914d\u5217\u3092\u4f7f\u7528\u3057\u3066\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u3001\u305d\u308c\u3092\u4f7f\u7528\u3057\u3066\u30bb\u30c3\u30c8\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>import java.util.*;\r\n\r\npublic class ArrayToSet {\r\n   public static void main(String[] args) {\r\n\t\t\r\n\tString[] vowels = {\"a\",\"e\",\"i\",\"o\",\"u\"};\r\n\t\t\r\n\tSet&lt;String&gt; vowelsSet = new HashSet&gt;(Arrays.asList(vowels));\r\n\tSystem.out.println(vowelsSet);\r\n\t\r\n\t\/**\r\n\t * Unlike List, Set is NOt backed by array, \r\n\t * so we can do structural modification without any issues.\r\n\t *\/\r\n\tvowelsSet.remove(\"e\");\r\n\tSystem.out.println(vowelsSet);\r\n\tvowelsSet.clear();\r\n\tSystem.out.println(vowelsSet);\r\n   }\r\n}\r\n<\/code><\/pre>\n<p>\u30a2\u30d7\u30ed\u30fc\u30c12\u3067\u306f\u3001\u4e2d\u9593\u30ea\u30b9\u30c8\u3092\u4f7f\u7528\u305b\u305a\u306b\u914d\u5217\u304b\u3089\u30bb\u30c3\u30c8\u3092\u4f5c\u6210\u3057\u307e\u305b\u3093\u3002\u307e\u305a\u3001\u7a7a\u306e\u30cf\u30c3\u30b7\u30e5\u30bb\u30c3\u30c8\u3092\u4f5c\u6210\u3057\u3001\u6b21\u306bCollections.addAll()\u3092\u4f7f\u7528\u3057\u3066\u914d\u5217\u306e\u8981\u7d20\u3092\u6307\u5b9a\u3055\u308c\u305f\u30bb\u30c3\u30c8\u306b\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306b\u793a\u3059\u65b9\u6cd5\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>import java.util.*;\r\n\r\npublic class ArrayToSet2 {\r\n   public static void main(String[] args) {\r\n\t\t\r\n\tString[] vowels = {\"a\",\"e\",\"i\",\"o\",\"u\"};\r\n\t\t\r\n\tSet&lt;String&gt; vowelsSet = new HashSet&lt;&gt;();\r\n\tCollections.addAll(vowelsSet, vowels); \r\n\tSystem.out.println(vowelsSet);\r\n\r\n\t\/** \r\n\t * Unlike List, Set is NOt backed by array, \r\n\t * so we can do structural modification without any issues.\r\n\t *\/\r\n\tvowelsSet.remove(\"e\");\r\n\tSystem.out.println(vowelsSet);\r\n\tvowelsSet.clear();\r\n\tSystem.out.println(vowelsSet);\r\n   }\r\n}\r\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e2\u3064\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306b\u793a\u3059\u3088\u3046\u306a\u540c\u3058\u51fa\u529b\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>[a, e, u, i, o]\r\n[a, u, i, o]\r\n[]\r\n<\/code><\/pre>\n<h3>Java\u306eSet\u3092\u914d\u5217\u306b\u5909\u63db\u3059\u308b<\/h3>\n<p>\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u4ee5\u4e0b\u306b\u793a\u3059\u3088\u3046\u306b\u3001Set.toArray()\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001\u6587\u5b57\u5217\u306e\u30bb\u30c3\u30c8\u3092\u6587\u5b57\u5217\u306e\u914d\u5217\u306b\u5909\u63db\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>import java.util.*;\r\n\r\npublic class SetToArray {\r\n   public static void main(String[] args) {\r\n\tSet&lt;String&lt; vowelsSet = new HashSet&lt;&gt;();\r\n\r\n\t\/\/ add example\r\n\tvowelsSet.add(\"a\");\r\n\tvowelsSet.add(\"e\");\r\n\tvowelsSet.add(\"i\");\r\n\tvowelsSet.add(\"o\");\r\n\tvowelsSet.add(\"u\");\r\n\t\t\r\n\t\/\/convert Set to Array\r\n\tString strArray[] = vowelsSet.toArray(new String[vowelsSet.size()]);\r\n\tSystem.out.println(Arrays.toString(strArray)); \r\n   }\r\n}\r\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306b\u793a\u3059\u51fa\u529b\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>[a, e, u, i, o]\r\n<\/code><\/pre>\n<h3>Java\u306eSet\u306e\u30bd\u30fc\u30c8\u65b9\u6cd5<\/h3>\n<p>\u79c1\u305f\u3061\u304c\u77e5\u3063\u3066\u3044\u308b\u3088\u3046\u306b\u3001\u30bb\u30c3\u30c8\uff08HashSet\uff09\u306f\u8981\u7d20\u306e\u76f4\u63a5\u7684\u306a\u30bd\u30fc\u30c8\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u307e\u305b\u3093\u3002\u30bb\u30c3\u30c8\u306f\u8981\u7d20\u3092\u30e9\u30f3\u30c0\u30e0\u306a\u9806\u5e8f\u3067\u4fdd\u6301\u3057\u3001\u8868\u793a\u3057\u307e\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u65b9\u6cd5\u3092\u4f7f\u3063\u3066\u8981\u7d20\u3092\u30bd\u30fc\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>import java.util.*;\r\n\r\npublic class SetSortingExample {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSet&lt;Integer&gt; intsSet = new HashSet&lt;&gt;();\r\n\t\tRandom random = new Random();\r\n\t\tfor (int i = 0; i  {return (o2-o1);});\r\n\t\tSystem.out.println(\"Reverse Sorting: \" + intsList2);\r\n\r\n\t\t\/\/ Approach-3\r\n\t\tSet&lt;Integer&gt; sortedSet = new TreeSet&lt;&gt;(intsSet);\r\n\t\tSystem.out.println(\"Sorted Set: \" + sortedSet);\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u51fa\u529b\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>[560, 864, 176, 657, 135, 103, 40, 123, 555, 589]\r\nNatural Sorting: [40, 103, 123, 135, 176, 555, 560, 589, 657, 864]\r\nBefore Sorting: [560, 864, 176, 657, 135, 103, 40, 123, 555, 589]\r\nReverse Sorting: [864, 657, 589, 560, 555, 176, 135, 123, 103, 40]\r\nSorted Set: [40, 103, 123, 135, 176, 555, 560, 589, 657, 864]\r\n<\/code><\/pre>\n<h3>Java\u306eSet\u306e\u5171\u901a\u64cd\u4f5c<\/h3>\n<p>Java Set\u306b\u5bfe\u3057\u3066\u4e00\u822c\u7684\u306b\u884c\u308f\u308c\u308b\u64cd\u4f5c\u306f\u3001add\u3001addAll\u3001clear\u3001size\u306a\u3069\u3067\u3059\u3002\u4ee5\u4e0b\u306f\u3001\u4e00\u822c\u7684\u306a\u30e1\u30bd\u30c3\u30c9\u306e\u4f7f\u7528\u4f8b\u3092\u793a\u3057\u305f\u30b7\u30f3\u30d7\u30eb\u306aJava Set\u306e\u4f8b\u3067\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>import java.util.*;\r\n\r\npublic class SetCommonOperations \r\n{\r\n   public static void main(String args[]) \r\n   {\r\n\tSet&lt;String&gt; vowels= new HashSet&lt;&gt;();\r\n\t\t\r\n\t\/\/add example\r\n\tvowels.add(\"A\");\r\n\tvowels.add(\"E\");\r\n\tvowels.add(\"I\");\r\n\r\n\t\/\/We cannot insert elements based on index to a Set\r\n\tSystem.out.println(vowels);\r\n\t\t\r\n\tSet&lt;String&gt; set = new HashSet&lt;&gt;();\r\n\tset.add(\"O\");\r\n\tset.add(\"U\");\r\n\t\r\n\t\/\/appending set elements to letters\r\n\tvowels.addAll(set);\r\n\tSystem.out.println(vowels);\r\n\t\r\n\t\/\/clear example to empty the set\r\n\tset.clear();\r\n\t\t\r\n\t\/\/size example\r\n\tSystem.out.println(\"letters set size = \" + vowels.size());\r\n\t\t\r\n\tvowels.clear();\r\n\tvowels.add(\"E\"); vowels.add(\"E\");vowels.add(\"I\"); vowels.add(\"O\");\r\n\tSystem.out.println(\"Given set contains E element or not? = \" + vowels.contains(\"E\"));\r\n\t\t\r\n   }\r\n}\r\n<\/code><\/pre>\n<p>\u7d50\u679c\uff1a<\/p>\n<pre class=\"post-pre\"><code>[A, E, I]\r\n[A, E, U, I, O]\r\nletters set size = 5\r\nGiven set contains E element or not? = true\r\n<\/code><\/pre>\n<h3>Java\u306e\u30bb\u30c3\u30c8\u30a4\u30c6\u30ec\u30fc\u30bf<\/h3>\n<p>\u4ee5\u4e0b\u306f\u3001Java\u306eSet\u3092\u7e70\u308a\u8fd4\u3059\u65b9\u6cd5\u306e\u30b7\u30f3\u30d7\u30eb\u306a\u4f8b\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>import java.util.*;\r\n\r\npublic class SetIteratorExample\r\n{\r\n   public static void main(String[] args) \r\n   {\r\n\r\n\tSet&lt;Integer&gt; set = new HashSet&lt;&gt;();\r\n\tfor(int i=0; i&lt;5; i++) \r\n\t\tset.add(i);\r\n\t\t\r\n\tIterator iterator = set.iterator();\r\n\t\r\n\t\/\/simple iteration\r\n\twhile(iterator.hasNext()){\r\n\t\tint i = (int) iterator.next();\r\n\t\tSystem.out.print(i + \", \");\r\n\t}\r\n\tSystem.out.println(\"\\n\" + set);\r\n\t\r\n\t\/\/modification of set using iterator\r\n\titerator = set.iterator();\r\n\twhile(iterator.hasNext()){\r\n\t\tint x = (int) iterator.next();\r\n\t\tif(x%2 ==0) iterator.remove();\r\n\t}\r\n\tSystem.out.println(set);\r\n\t\t\r\n\t\/\/changing set structure while iterating\r\n\titerator = set.iterator();\r\n\twhile(iterator.hasNext()){\r\n                \/\/ConcurrentModificationException here\r\n\t\tint x = (int) iterator.next(); \r\n\t\tif(x==1) set.add(10);\r\n\t}\r\n   }\r\n}\r\n<\/code><\/pre>\n<h3>Java\u306eSet\u3092Stream\u306b\u5909\u63db\u3059\u308b<\/h3>\n<p>\u4ee5\u4e0b\u306f\u3001Java\u306eSet\u3092Stream\u306b\u5909\u63db\u3057\u3001\u8981\u4ef6\u306b\u5fdc\u3058\u3066\u3044\u304f\u3064\u304b\u306e\u64cd\u4f5c\u3092\u884c\u3046\u65b9\u6cd5\u3092\u793a\u3059\u30b7\u30f3\u30d7\u30eb\u306a\u4f8b\u3067\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>import java.util.*;\r\n\r\npublic class SetToStream {\r\n\r\n   public static void main(String[] args) {\r\n\tSet&lt;String&gt; vowelsSet = new HashSet&lt;&gt;();\r\n\t\/\/ add example\r\n\tvowelsSet.add(\"a\");\r\n\tvowelsSet.add(\"e\");\r\n\tvowelsSet.add(\"i\");\r\n\tvowelsSet.add(\"o\");\r\n\tvowelsSet.add(\"u\");\r\n\t\t\r\n\t\/\/convert set to stream\r\n\tvowelsSet.stream().forEach(System.out::println);\r\n   }\r\n}\r\n<\/code><\/pre>\n<p>\u7d50\u679c: &#8211; \u51fa\u529b<\/p>\n<pre class=\"post-pre\"><code>a\r\ne\r\nu\r\ni\r\no\r\n<\/code><\/pre>\n<h3>Java SE 9\u306e\u30bb\u30c3\u30c8<\/h3>\n<p>Java SE 9\u306e\u30ea\u30ea\u30fc\u30b9\u3067\u306f\u3001Oracle Corp\u306fSet\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306b\u3044\u304f\u3064\u304b\u306e\u4fbf\u5229\u306a\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u4e88\u5b9a\u3067\u3059\u3002\u3053\u308c\u3089\u3092\u7406\u89e3\u3059\u308b\u305f\u3081\u306b\u3001\u3044\u304f\u3064\u304b\u306e\u30b7\u30f3\u30d7\u30eb\u3067\u4f7f\u3044\u3084\u3059\u3044\u4f8b\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002\u300cJava SE 9\uff1a\u30bb\u30c3\u30c8\u306e\u751f\u6210\u30e1\u30bd\u30c3\u30c9\u300d\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u3054\u89a7\u3044\u305f\u3060\u304d\u3001\u305c\u3072\u5b66\u7fd2\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u308c\u306b\u3066Java\u306eSet\u306b\u95a2\u3059\u308b\u7c21\u5358\u306a\u307e\u3068\u3081\u3068\u306a\u308a\u307e\u3059\u3002\u3053\u308c\u3089\u306eJava Set\u306e\u4f8b\u304c\u3001\u30bb\u30c3\u30c8\u306e\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u521d\u6b69\u306b\u5f79\u7acb\u3064\u3053\u3068\u3092\u9858\u3063\u3066\u3044\u307e\u3059\u3002\u79c1\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u304a\u8aad\u307f\u3044\u305f\u3060\u304d\u3001\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3057\u305f\u3002\u3082\u3057\u3082\u79c1\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u304c\u6c17\u306b\u5165\u3063\u305f\u308a\u3001\u554f\u984c\u3084\u63d0\u6848\u3001\u30bf\u30a4\u30d7\u306e\u30a8\u30e9\u30fc\u306a\u3069\u304c\u3042\u308a\u307e\u3057\u305f\u3089\u3001\u30b3\u30e1\u30f3\u30c8\u3092\u6295\u7a3f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java Set (\u30b8\u30e3\u30f4\u30a1\u30fb\u30bb\u30c3\u30c8) \u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001Java\u306eSet\u306b\u3064\u3044\u3066\u306e\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u306b\u3064\u3044\u3066\u8b70\u8ad6\u3057\u307e\u3059\u3002 Java Set interface is a member of the Java Collec [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[26,61],"class_list":["post-402","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-26","tag-61"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u306eSet\u306f\u3001Java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002 - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Java\u306eSet\u306fJava\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/ja\/blog\/java\u306eset\u306f\u3001java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u306eSet\u306f\u3001Java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002\" \/>\n<meta property=\"og:description\" content=\"Java\u306eSet\u306fJava\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/ja\/blog\/java\u306eset\u306f\u3001java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-21T05:48:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T14:18:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/65648bf0daa94e2bdf7bc351\/0-0.png\" \/>\n<meta name=\"author\" content=\"\u590f\u6a39, \u98a8\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u590f\u6a39, \u98a8\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"15\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/\",\"name\":\"Java\u306eSet\u306f\u3001Java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\"},\"datePublished\":\"2023-10-21T05:48:05+00:00\",\"dateModified\":\"2025-07-31T14:18:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/4e591db2661c4cc425470b461259391d\"},\"description\":\"Java\u306eSet\u306fJava\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/ja\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u306eSet\u306f\u3001Java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/4e591db2661c4cc425470b461259391d\",\"name\":\"\u590f\u6a39, \u98a8\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/65e0ff40534461b1fa000382dc194e1716f793ab0bcb218ac3c40895551a08c5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/65e0ff40534461b1fa000382dc194e1716f793ab0bcb218ac3c40895551a08c5?s=96&d=mm&r=g\",\"caption\":\"\u590f\u6a39, \u98a8\"},\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/author\/natsukikaze\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java\u306eSet\u306f\u3001Java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002 - Blog - Silicon Cloud","description":"Java\u306eSet\u306fJava\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/ja\/blog\/java\u306eset\u306f\u3001java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002\/","og_locale":"ja_JP","og_type":"article","og_title":"Java\u306eSet\u306f\u3001Java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002","og_description":"Java\u306eSet\u306fJava\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","og_url":"https:\/\/www.silicloud.com\/ja\/blog\/java\u306eset\u306f\u3001java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-10-21T05:48:05+00:00","article_modified_time":"2025-07-31T14:18:48+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/65648bf0daa94e2bdf7bc351\/0-0.png"}],"author":"\u590f\u6a39, \u98a8","twitter_card":"summary_large_image","twitter_misc":{"\u57f7\u7b46\u8005":"\u590f\u6a39, \u98a8","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"15\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/","url":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/","name":"Java\u306eSet\u306f\u3001Java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website"},"datePublished":"2023-10-21T05:48:05+00:00","dateModified":"2025-07-31T14:18:48+00:00","author":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/4e591db2661c4cc425470b461259391d"},"description":"Java\u306eSet\u306fJava\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/ja\/blog\/"},{"@type":"ListItem","position":2,"name":"Java\u306eSet\u306f\u3001Java\u306e\u30bb\u30c3\u30c8\u3067\u3059\u3002"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website","url":"https:\/\/www.silicloud.com\/ja\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/4e591db2661c4cc425470b461259391d","name":"\u590f\u6a39, \u98a8","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/65e0ff40534461b1fa000382dc194e1716f793ab0bcb218ac3c40895551a08c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/65e0ff40534461b1fa000382dc194e1716f793ab0bcb218ac3c40895551a08c5?s=96&d=mm&r=g","caption":"\u590f\u6a39, \u98a8"},"url":"https:\/\/www.silicloud.com\/ja\/blog\/author\/natsukikaze\/"},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/java%e3%81%aeset%e3%81%af%e3%80%81java%e3%81%ae%e3%82%bb%e3%83%83%e3%83%88%e3%81%a7%e3%81%99%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/comments?post=402"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/402\/revisions"}],"predecessor-version":[{"id":40140,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/402\/revisions\/40140"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/media?parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/categories?post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/tags?post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}