0

I want to shuffle my array which is in an array, but only the first array

String[][] kaarten = {  {"G", "T","1"}, 
                        {"G", "T","2"},
                        {"G", "T","3"},
                        //green triangle
                        {"R", "T","1"},
                        {"R", "T","2"},
                        {"R", "T","3"},
                        //red triangle
                        {"B", "T","1"},
                        {"B", "T","2"},
                        {"B", "T","3"},
                        //blue triangle
                        {"G", "O","1"},
                        {"G", "O","2"},
                        {"G", "O","3"},
                        //green Oval
                        {"R", "T","1"},
                        {"R", "T","2"},
                        {"R", "T","3"},
                        //Red Oval
                        {"B", "T","1"},
                        {"B", "T","2"},
                        {"B", "T","3"},
                        //Blue Oval
                        {"G", "S","1"},
                        {"G", "S","2"},
                        {"G", "S","3"},
                        //green Square
                        {"R", "T","1"},
                        {"R", "T","2"},
                        {"R", "T","3"},
                        //Red Square
                        {"B", "T","1"},
                        {"B", "T","2"},
                        {"B", "T","3"},
                        //Blue Square
                      };

So the {"G", "T", "1"} needs to stay the same.

I hope you understand what I am seeing, it's kinda hard to explain.

3
  • Oh and please also edit your question to add the appropriate language tag. Commented Jan 23, 2019 at 12:38
  • please explain what actually you are looking for. Commented Jan 23, 2019 at 13:09
  • I want the array to be shuffled without the array which in it is being shuffled @Raúl Commented Jan 23, 2019 at 13:43

1 Answer 1

3

The easiest way would be to create a list of String[] and use Collections.shuffle():

List<String[]> values = new ArrayList<>();
Collections.addAll(values, kaarten);
Collections.shuffle(values);
values.stream().map(Arrays::toString).forEach(System.out::println);

will show that values was randomly rearranged without modifying the internal String[]:

[G, O, 3] 
[R, T, 3]
[G, O, 2]
[R, T, 3]
[R, T, 1]
... 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.