title: How can I equally divide a name list into 2 or 4 groups and print them out?
body: <p>I have a list of 4 names that I want to divide into 2 groups of 2 each.</p>
  
  <pre><code>//the variables are defined by user input
  
  String name1=null, name2=null, name3=null, name4=null;
  
  //Now i need something to choose 2 random names and print them out 
  
  System.out.println("Team A = name 1, name 2");
  System.out.println("Team B = name 3, name 4");
  </code></pre>
  
  <p>etc.</p>
  
  <p>It needs to be completely random. For when I add more names. It should take different group each time, and a name can only be used once.</p>
  
  <p>I have tried with this:</p>
  
  <pre><code>List&lt;String&gt; list = new ArrayList&lt;&gt;(); 
  
   list.add(name1); 
   list.add(name2); 
   list.add(name3); 
   list.add(name4); 
  
   selecto obj = new selecto(); 
  
   System.out.println(obj.getRandomElement(list)); 
   } 
  
   public int getRandomElement(List&lt;Integer&gt; list) 
   { 
      Random rand = new Random(); 
      return list.get(rand.nextInt(list.size())); 
  </code></pre>
  
  <p>This works perfectly with the integer but not strings.</p>