0

So far I have the following, as I am slowly learning Java. I am building a very simple utility that will let me (eventually) enter names in the console and shuffle those names pairing them up. As of now all this does is shuffle the array of names. I want to be able to slice or limit (return) 2 names at a time, this would remove them from the array (or didn't have to) then return the next two. and so on.

package com.company;

import java.util.Arrays;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        // eventually have user type names instead as the number of names will change
        String[] names = new String[] {"Jack", "Jill", "James", "Jose", "Jason", "Self"};
        Collections.shuffle(Arrays.asList(names));

        System.out.println(Arrays.asList("names));
    }
}
Diego
  • 594
  • 2
  • 10
  • 29
  • I believe you misunderstood my question Sotirios, I do NOT want to split an array into smaller arrays, I want to get and return two elements (strings) of an array. – Diego Jun 21 '16 at 21:26
  • I based my vote on _this would remove them from the array (or didn't have to) then return the next two. and so on_. That's what the division in the linked duplicate does. It provides consecutive partitions (sublist views) from a given list. – Sotirios Delimanolis Jun 21 '16 at 21:28
  • Right, whatever method applied on Collections would or would not remove the strings from the array to me it doesn't matter. As long as I can 1. print the names in pair, or 2. get to their index to print them. or 3. delete them as they have been paired that way i dont have to care about their indexes. – Diego Jun 21 '16 at 21:33
  • Take a look at the duplicate again. The solutions there provide consecutive tuples (can be pairs) from your original list. You can iterate over them and print the elements of the tuples. – Sotirios Delimanolis Jun 21 '16 at 21:38

0 Answers0