{"id":103,"date":"2007-10-31T15:04:18","date_gmt":"2007-10-31T20:04:18","guid":{"rendered":"http:\/\/stein.everybody.org\/brain\/create-a-list-of-one-item\/"},"modified":"2011-03-10T10:57:28","modified_gmt":"2011-03-10T15:57:28","slug":"create-a-list-of-one-item","status":"publish","type":"post","link":"https:\/\/jeremystein.com\/brain\/create-a-list-of-one-item\/","title":{"rendered":"Create a list of one item in Java"},"content":{"rendered":"<p>Sometimes you need to call a method that takes a collection, but you just want to send it one value.  You wish you didn&#8217;t have to do this:<\/p>\n<pre>List tempList = new ArrayList&lt;MyClass&gt;(1);\ntempList.add(value);<\/pre>\n<p>You can do it all in one expression.  Here is a Java idiom for creating a collection with a single item in it:<\/p>\n<pre>Arrays.asList(new MyClass[] {value})<\/pre>\n<p>In Java 1.5 you can simplify that to:<\/p>\n<pre>Arrays.asList(value)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you need to call a method that takes a collection, but you just want to send it one value. You wish you didn&#8217;t have to do this: List tempList = new ArrayList&lt;MyClass&gt;(1); tempList.add(value); You can do it all in one expression. Here is a Java idiom for creating a collection with a single item [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":0,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"wp:attachment":[{"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jeremystein.com\/brain\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}