How to make a dynamic 2D array and store a shuffled array in it
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I've created a 2D arraylist that has a fixed number or rows and an array that holds numbers 1-4. I'm supposed to shuffle the array and then store that array in the arraylist. However, when I go to print the entire arraylist after, it doesn't match, and it appears, it is taking my last shuffle and printing it for all the rows.
For example, one of my outputs is:
3, 2, 1, 4
1, 2, 4, 3
2, 1, 3, 4
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
Can someone help me understand my mistake?
package practice;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
//Array for team numbers
Integer teamNums = new Integer {
1,
2,
3,
4
};
for (int i = 0; i < 4; i++) {
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(teamMatches.get(i)[0] + ", " + teamMatches.get(i)[1] + ", " +
teamMatches.get(i)[2] + ", " + teamMatches.get(i)[3]);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(teamMatches.get(n)[0] + ", " + teamMatches.get(n)[1] + ", " +
teamMatches.get(n)[2] + ", " + teamMatches.get(n)[3]);
}
}
java arrays multidimensional-array dynamic shuffle
add a comment |
I've created a 2D arraylist that has a fixed number or rows and an array that holds numbers 1-4. I'm supposed to shuffle the array and then store that array in the arraylist. However, when I go to print the entire arraylist after, it doesn't match, and it appears, it is taking my last shuffle and printing it for all the rows.
For example, one of my outputs is:
3, 2, 1, 4
1, 2, 4, 3
2, 1, 3, 4
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
Can someone help me understand my mistake?
package practice;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
//Array for team numbers
Integer teamNums = new Integer {
1,
2,
3,
4
};
for (int i = 0; i < 4; i++) {
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(teamMatches.get(i)[0] + ", " + teamMatches.get(i)[1] + ", " +
teamMatches.get(i)[2] + ", " + teamMatches.get(i)[3]);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(teamMatches.get(n)[0] + ", " + teamMatches.get(n)[1] + ", " +
teamMatches.get(n)[2] + ", " + teamMatches.get(n)[3]);
}
}
java arrays multidimensional-array dynamic shuffle
Do you just want to shuffle the arrays of array or the elements in each array??? What would be the expected result?
– c-an
Nov 17 '18 at 3:18
I only want to shuffle the teamNums array. After that, I want to put the shuffled array into the teamMatches arraylist. My expected result is that the first loop prints out a 4x4 array with each row containing numbers 1-4 in a random order without repeats. The second loop is just there to check if the shuffled arrays are being stored correctly. If the two printed arrays match, then I know that I'm storing my shuffled array in the correct order
– Lizzy Lu
Nov 17 '18 at 4:24
add a comment |
I've created a 2D arraylist that has a fixed number or rows and an array that holds numbers 1-4. I'm supposed to shuffle the array and then store that array in the arraylist. However, when I go to print the entire arraylist after, it doesn't match, and it appears, it is taking my last shuffle and printing it for all the rows.
For example, one of my outputs is:
3, 2, 1, 4
1, 2, 4, 3
2, 1, 3, 4
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
Can someone help me understand my mistake?
package practice;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
//Array for team numbers
Integer teamNums = new Integer {
1,
2,
3,
4
};
for (int i = 0; i < 4; i++) {
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(teamMatches.get(i)[0] + ", " + teamMatches.get(i)[1] + ", " +
teamMatches.get(i)[2] + ", " + teamMatches.get(i)[3]);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(teamMatches.get(n)[0] + ", " + teamMatches.get(n)[1] + ", " +
teamMatches.get(n)[2] + ", " + teamMatches.get(n)[3]);
}
}
java arrays multidimensional-array dynamic shuffle
I've created a 2D arraylist that has a fixed number or rows and an array that holds numbers 1-4. I'm supposed to shuffle the array and then store that array in the arraylist. However, when I go to print the entire arraylist after, it doesn't match, and it appears, it is taking my last shuffle and printing it for all the rows.
For example, one of my outputs is:
3, 2, 1, 4
1, 2, 4, 3
2, 1, 3, 4
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
2, 3, 4, 1
Can someone help me understand my mistake?
package practice;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
//Array for team numbers
Integer teamNums = new Integer {
1,
2,
3,
4
};
for (int i = 0; i < 4; i++) {
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(teamMatches.get(i)[0] + ", " + teamMatches.get(i)[1] + ", " +
teamMatches.get(i)[2] + ", " + teamMatches.get(i)[3]);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(teamMatches.get(n)[0] + ", " + teamMatches.get(n)[1] + ", " +
teamMatches.get(n)[2] + ", " + teamMatches.get(n)[3]);
}
}
package practice;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
//Array for team numbers
Integer teamNums = new Integer {
1,
2,
3,
4
};
for (int i = 0; i < 4; i++) {
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(teamMatches.get(i)[0] + ", " + teamMatches.get(i)[1] + ", " +
teamMatches.get(i)[2] + ", " + teamMatches.get(i)[3]);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(teamMatches.get(n)[0] + ", " + teamMatches.get(n)[1] + ", " +
teamMatches.get(n)[2] + ", " + teamMatches.get(n)[3]);
}
}
package practice;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
//Array for team numbers
Integer teamNums = new Integer {
1,
2,
3,
4
};
for (int i = 0; i < 4; i++) {
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(teamMatches.get(i)[0] + ", " + teamMatches.get(i)[1] + ", " +
teamMatches.get(i)[2] + ", " + teamMatches.get(i)[3]);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(teamMatches.get(n)[0] + ", " + teamMatches.get(n)[1] + ", " +
teamMatches.get(n)[2] + ", " + teamMatches.get(n)[3]);
}
}
java arrays multidimensional-array dynamic shuffle
java arrays multidimensional-array dynamic shuffle
edited Nov 17 '18 at 3:10
Ori Drori
83k148998
83k148998
asked Nov 17 '18 at 2:56
Lizzy LuLizzy Lu
154
154
Do you just want to shuffle the arrays of array or the elements in each array??? What would be the expected result?
– c-an
Nov 17 '18 at 3:18
I only want to shuffle the teamNums array. After that, I want to put the shuffled array into the teamMatches arraylist. My expected result is that the first loop prints out a 4x4 array with each row containing numbers 1-4 in a random order without repeats. The second loop is just there to check if the shuffled arrays are being stored correctly. If the two printed arrays match, then I know that I'm storing my shuffled array in the correct order
– Lizzy Lu
Nov 17 '18 at 4:24
add a comment |
Do you just want to shuffle the arrays of array or the elements in each array??? What would be the expected result?
– c-an
Nov 17 '18 at 3:18
I only want to shuffle the teamNums array. After that, I want to put the shuffled array into the teamMatches arraylist. My expected result is that the first loop prints out a 4x4 array with each row containing numbers 1-4 in a random order without repeats. The second loop is just there to check if the shuffled arrays are being stored correctly. If the two printed arrays match, then I know that I'm storing my shuffled array in the correct order
– Lizzy Lu
Nov 17 '18 at 4:24
Do you just want to shuffle the arrays of array or the elements in each array??? What would be the expected result?
– c-an
Nov 17 '18 at 3:18
Do you just want to shuffle the arrays of array or the elements in each array??? What would be the expected result?
– c-an
Nov 17 '18 at 3:18
I only want to shuffle the teamNums array. After that, I want to put the shuffled array into the teamMatches arraylist. My expected result is that the first loop prints out a 4x4 array with each row containing numbers 1-4 in a random order without repeats. The second loop is just there to check if the shuffled arrays are being stored correctly. If the two printed arrays match, then I know that I'm storing my shuffled array in the correct order
– Lizzy Lu
Nov 17 '18 at 4:24
I only want to shuffle the teamNums array. After that, I want to put the shuffled array into the teamMatches arraylist. My expected result is that the first loop prints out a 4x4 array with each row containing numbers 1-4 in a random order without repeats. The second loop is just there to check if the shuffled arrays are being stored correctly. If the two printed arrays match, then I know that I'm storing my shuffled array in the correct order
– Lizzy Lu
Nov 17 '18 at 4:24
add a comment |
1 Answer
1
active
oldest
votes
When you are adding your teamNums to teamMatches, you are passing the reference (pointer) to the same array (same memory location). Therefore when you print after the for loop you will only get the last known shuffle because that's what the array looks like.
You must declare a new array variable for each iteration of the for loop.
Try :
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
for (int i = 0; i < 4; i++) {
// *create new Array for team numbers
Integer teamNums = new Integer {1, 2, 3, 4};
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(
teamMatches.get(i)[0] + ", "
+ teamMatches.get(i)[1] + ", "
+ teamMatches.get(i)[2] + ", "
+ teamMatches.get(i)[3]
);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(
teamMatches.get(n)[0] + ", "
+ teamMatches.get(n)[1] + ", "
+ teamMatches.get(n)[2] + ", "
+ teamMatches.get(n)[3]);
}
}
}
Alright thank you! This solved my issue. Just for my understanding/clarification, before, I was essentially only printing out the last shuffle after the loop because that was the only thing that could be referenced?
– Lizzy Lu
Nov 17 '18 at 4:22
1
Yes. You were essentially adding the same array (same memory location) to teamMatches. So while each iteration of your for loop was shuffling the array, when you print out the array after the for loop you were printing out only the last shuffle because all your previous shuffles were being overwritten. Please upvote the answer if it helped.
– John Kim
Nov 17 '18 at 4:35
I've upvoted, but since I don't have enough reputation it does not display publicly. Thank you for all the help!
– Lizzy Lu
Nov 17 '18 at 12:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347791%2fhow-to-make-a-dynamic-2d-array-and-store-a-shuffled-array-in-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you are adding your teamNums to teamMatches, you are passing the reference (pointer) to the same array (same memory location). Therefore when you print after the for loop you will only get the last known shuffle because that's what the array looks like.
You must declare a new array variable for each iteration of the for loop.
Try :
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
for (int i = 0; i < 4; i++) {
// *create new Array for team numbers
Integer teamNums = new Integer {1, 2, 3, 4};
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(
teamMatches.get(i)[0] + ", "
+ teamMatches.get(i)[1] + ", "
+ teamMatches.get(i)[2] + ", "
+ teamMatches.get(i)[3]
);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(
teamMatches.get(n)[0] + ", "
+ teamMatches.get(n)[1] + ", "
+ teamMatches.get(n)[2] + ", "
+ teamMatches.get(n)[3]);
}
}
}
Alright thank you! This solved my issue. Just for my understanding/clarification, before, I was essentially only printing out the last shuffle after the loop because that was the only thing that could be referenced?
– Lizzy Lu
Nov 17 '18 at 4:22
1
Yes. You were essentially adding the same array (same memory location) to teamMatches. So while each iteration of your for loop was shuffling the array, when you print out the array after the for loop you were printing out only the last shuffle because all your previous shuffles were being overwritten. Please upvote the answer if it helped.
– John Kim
Nov 17 '18 at 4:35
I've upvoted, but since I don't have enough reputation it does not display publicly. Thank you for all the help!
– Lizzy Lu
Nov 17 '18 at 12:58
add a comment |
When you are adding your teamNums to teamMatches, you are passing the reference (pointer) to the same array (same memory location). Therefore when you print after the for loop you will only get the last known shuffle because that's what the array looks like.
You must declare a new array variable for each iteration of the for loop.
Try :
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
for (int i = 0; i < 4; i++) {
// *create new Array for team numbers
Integer teamNums = new Integer {1, 2, 3, 4};
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(
teamMatches.get(i)[0] + ", "
+ teamMatches.get(i)[1] + ", "
+ teamMatches.get(i)[2] + ", "
+ teamMatches.get(i)[3]
);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(
teamMatches.get(n)[0] + ", "
+ teamMatches.get(n)[1] + ", "
+ teamMatches.get(n)[2] + ", "
+ teamMatches.get(n)[3]);
}
}
}
Alright thank you! This solved my issue. Just for my understanding/clarification, before, I was essentially only printing out the last shuffle after the loop because that was the only thing that could be referenced?
– Lizzy Lu
Nov 17 '18 at 4:22
1
Yes. You were essentially adding the same array (same memory location) to teamMatches. So while each iteration of your for loop was shuffling the array, when you print out the array after the for loop you were printing out only the last shuffle because all your previous shuffles were being overwritten. Please upvote the answer if it helped.
– John Kim
Nov 17 '18 at 4:35
I've upvoted, but since I don't have enough reputation it does not display publicly. Thank you for all the help!
– Lizzy Lu
Nov 17 '18 at 12:58
add a comment |
When you are adding your teamNums to teamMatches, you are passing the reference (pointer) to the same array (same memory location). Therefore when you print after the for loop you will only get the last known shuffle because that's what the array looks like.
You must declare a new array variable for each iteration of the for loop.
Try :
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
for (int i = 0; i < 4; i++) {
// *create new Array for team numbers
Integer teamNums = new Integer {1, 2, 3, 4};
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(
teamMatches.get(i)[0] + ", "
+ teamMatches.get(i)[1] + ", "
+ teamMatches.get(i)[2] + ", "
+ teamMatches.get(i)[3]
);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(
teamMatches.get(n)[0] + ", "
+ teamMatches.get(n)[1] + ", "
+ teamMatches.get(n)[2] + ", "
+ teamMatches.get(n)[3]);
}
}
}
When you are adding your teamNums to teamMatches, you are passing the reference (pointer) to the same array (same memory location). Therefore when you print after the for loop you will only get the last known shuffle because that's what the array looks like.
You must declare a new array variable for each iteration of the for loop.
Try :
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
public class Practice {
public static void main(String args) {
//Make arraylist for teams
List < Integer > teamMatches = new ArrayList < > ();
for (int i = 0; i < 4; i++) {
// *create new Array for team numbers
Integer teamNums = new Integer {1, 2, 3, 4};
//shuffle array
Collections.shuffle(Arrays.asList(teamNums));
//add array to arraylist
teamMatches.add(teamNums);
//print out
System.out.println(
teamMatches.get(i)[0] + ", "
+ teamMatches.get(i)[1] + ", "
+ teamMatches.get(i)[2] + ", "
+ teamMatches.get(i)[3]
);
}
System.out.println("_____________________________");
//print out entire match array
for (int n = 0; n < 4; n++) {
System.out.println(
teamMatches.get(n)[0] + ", "
+ teamMatches.get(n)[1] + ", "
+ teamMatches.get(n)[2] + ", "
+ teamMatches.get(n)[3]);
}
}
}
edited Nov 17 '18 at 6:35
c-an
572526
572526
answered Nov 17 '18 at 3:15
John KimJohn Kim
413211
413211
Alright thank you! This solved my issue. Just for my understanding/clarification, before, I was essentially only printing out the last shuffle after the loop because that was the only thing that could be referenced?
– Lizzy Lu
Nov 17 '18 at 4:22
1
Yes. You were essentially adding the same array (same memory location) to teamMatches. So while each iteration of your for loop was shuffling the array, when you print out the array after the for loop you were printing out only the last shuffle because all your previous shuffles were being overwritten. Please upvote the answer if it helped.
– John Kim
Nov 17 '18 at 4:35
I've upvoted, but since I don't have enough reputation it does not display publicly. Thank you for all the help!
– Lizzy Lu
Nov 17 '18 at 12:58
add a comment |
Alright thank you! This solved my issue. Just for my understanding/clarification, before, I was essentially only printing out the last shuffle after the loop because that was the only thing that could be referenced?
– Lizzy Lu
Nov 17 '18 at 4:22
1
Yes. You were essentially adding the same array (same memory location) to teamMatches. So while each iteration of your for loop was shuffling the array, when you print out the array after the for loop you were printing out only the last shuffle because all your previous shuffles were being overwritten. Please upvote the answer if it helped.
– John Kim
Nov 17 '18 at 4:35
I've upvoted, but since I don't have enough reputation it does not display publicly. Thank you for all the help!
– Lizzy Lu
Nov 17 '18 at 12:58
Alright thank you! This solved my issue. Just for my understanding/clarification, before, I was essentially only printing out the last shuffle after the loop because that was the only thing that could be referenced?
– Lizzy Lu
Nov 17 '18 at 4:22
Alright thank you! This solved my issue. Just for my understanding/clarification, before, I was essentially only printing out the last shuffle after the loop because that was the only thing that could be referenced?
– Lizzy Lu
Nov 17 '18 at 4:22
1
1
Yes. You were essentially adding the same array (same memory location) to teamMatches. So while each iteration of your for loop was shuffling the array, when you print out the array after the for loop you were printing out only the last shuffle because all your previous shuffles were being overwritten. Please upvote the answer if it helped.
– John Kim
Nov 17 '18 at 4:35
Yes. You were essentially adding the same array (same memory location) to teamMatches. So while each iteration of your for loop was shuffling the array, when you print out the array after the for loop you were printing out only the last shuffle because all your previous shuffles were being overwritten. Please upvote the answer if it helped.
– John Kim
Nov 17 '18 at 4:35
I've upvoted, but since I don't have enough reputation it does not display publicly. Thank you for all the help!
– Lizzy Lu
Nov 17 '18 at 12:58
I've upvoted, but since I don't have enough reputation it does not display publicly. Thank you for all the help!
– Lizzy Lu
Nov 17 '18 at 12:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347791%2fhow-to-make-a-dynamic-2d-array-and-store-a-shuffled-array-in-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you just want to shuffle the arrays of array or the elements in each array??? What would be the expected result?
– c-an
Nov 17 '18 at 3:18
I only want to shuffle the teamNums array. After that, I want to put the shuffled array into the teamMatches arraylist. My expected result is that the first loop prints out a 4x4 array with each row containing numbers 1-4 in a random order without repeats. The second loop is just there to check if the shuffled arrays are being stored correctly. If the two printed arrays match, then I know that I'm storing my shuffled array in the correct order
– Lizzy Lu
Nov 17 '18 at 4:24