title: All combinations of pairs within one set
body: <p>I want to compute all possible lists of pairs you could make of a set. For instance:</p>
  
  <pre><code>input = [1, 2, 3, 4, 5, 6]
  
  output = {[(1,2), (3,4), (5,6)],
            [(2,3), (4,5), (1,6)],
            [(2,4), (1,3), (5,6)],
            [...], .... }
  </code></pre>
  
  <p>Note: this example are just some random things in the output, most is removed. I don't care about the order of the lists or the pairs within those lists. </p>
  
  <p>I think there would be <code>(n-1)(n-3)(n-5)...</code> possible lists of pairs. First I thought you could make all permutations of the input list. With all those permutations you could group the first with the second item and the third with fourth. But obviously that is very inefficient, because you would make <code>n!</code> items in the list and you would only need <code>(n-1)(n-3)(n-5)...</code>. Could some give me a hint how to do this more efficiently? Is there a known algorithm or what would the proper keywords to search with? I want to implement this in JAVA, so if you want to make use of the Collections class in JAVA no problem :)</p>
  
  <p>To be more clear: the input always consist of a even number of elements so all pairs in one list together are all elements in the input. </p>
  
  <p><strong>Edit:</strong>
  I have look to all answer. Now I have working code thanks for that. But I need to use it for a input with size <code>n = 26</code> :(. I have not implemented everything yet, but I guess it's going to run for a while :(.</p>