I am trying to split an ArrayList called mainarray into two other ArrayList's

• ArrayList called array1
• Arraylist called array2

In the mainarray I have exactly 12 values:

• "1"
• "2"
• "3"
• ...

How can I split them up so there are 2 random values in array1 and 10 random values in array2

Thank you for your help!

you can use `mainarray.size()` to find the size of your main ArrayList.

if you want the ratio to be 1:5, there will be 6 total divisions. so use two `for` loops: one with a range of 1 to size/6, the other with a range of (size/6)+1 to 6*(size/6).

In your example there are 12 elements in your array, so this method will give you 1 and 2 in your `array1` and 3 to 12 in your `array2`.

Just get two random values from one list and add to another.

``````Random r = new Random();
``````

Try to use this:
This code select from ArrayList `numbers` select 2/10 element2 to add at `head` and add 10 elements at `tail`:

``````  public static void main(String[] args)
{
List<Integer> numbers = new ArrayList<Integer>();

List<Integer> head = new ArrayList<Integer>();
List<Integer> tail = new ArrayList<Integer>();
for(int i = 1; i<=numbers.size(); i++){
if(i%6==0){
}
else{