We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I am stumped. This should be simple. I am trying to access the entire sublists/shortlists (not sure what they are called) that make up my 2D array. All of the reference I have seen shows me how to simply select/ print row/column items from the array. Thanks
int brobes[][] = {{0, 1, 0}, {4, 4, 4}, {4, 5, 5}, {6, 7, 8}};
int my0[] = brobes[0];
println(brobes[0]);
//hoping it will print: {0,1,0} and so forth
Answers
i think println has been overridden to print arrays like that.
i tried
println("" + brobes[0]);
(converting it to a string first) but that's not right either.System.out.println(brobes[0]);
didn't work either.you'll need to write your own method to display arrays.
hmmm... well my goal is to actually access each sublist. Still, should I write a method?
brobes[0] is the first 'sublist', it's just that it displays 'incorrectly'
this will format it how you want it
How about a more modern way to stringify arrays w/ Java 8's newest StringJoiner class: :)>-
http://docs.Oracle.com/javase/8/docs/api/java/util/StringJoiner.html
Great thanks! This very educational.
So, the end goal has been to define the 2D array and then run through my elementary CA script and choose a different ruleset each time. I am struggling, but I think I am close. Any insight would be appreciated. I am stuck on how to insert a new rule after my end condition is met.
Oh man.....
There are 2 Tutorials on Arrays - have a look on processing.org
Does the first generation work?
I mean line 87 gives you only a line of rects per generation (whereas the classic game of life gives you a grid for each Generation) nvm
Thanks @ Chrisir. I should have been clearer. This is the one dimensional CA so no game of life. I actually figured out how to randomly restart it. It is really just the concept of grabbing a different sublist of an array that is tricky for me. Thanks again.
Just come back if you still need help on this
IMPORTANT ADDENDUM
Class Arrays' toString() method already does the very same "stringify" for arrays:
http://docs.Oracle.com/javase/8/docs/api/java/util/Arrays.html#toString-int:A-
Therefore we don't need to implement that ourselves.
Only con is that we can't pick which prefix & suffix characters to be used. It's always
[
&]
. L-)@ Chrisir - I appreciate the help. @GoToLoop - this 'toString()' method is fantastic! Nice technique. Thank you to you both.