We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have an arraylist of strings that contains values of 0 and 1. I want to split the arraylist to multiples of 8 and store them seperately in another arraylist. For example, i have a arraylist of 0 and 1s. I take the first 8 digits then store in array, then the next 8 store into second index of the second array. If that makes any sense.
I have seen the split() function but I haven't figured out using on an arraylist.
Answers
You can't.
Just use a for loop and split it however you want.
its more clear if i rephrase my question as. How do i split an arraylist at every nth position and store in an array?
Example
Input - ArrayList = [0,1,1,0,1,0,1,0,1,0,1,0,0,0,1,1,0]
if n = 8, i take every nth position and store into array so
Output - Array =[011010101, 01000110]
thanks TfGuy44 for the reply but can i ask what does char('0'+in[i]); means?
My more complicated solution too. A little l8 for the party it seems: :O)
GoToLoops it does seem more complicated :)) i'll try to slowly dissect your code thanks for reply
I get an error called "The method parseChar(byte) is the type PApplet is not application for the arguments (String)"
What does this mean?
byte
isn't acceptable for PApplet's parseChar() method.int[]
is used as source.http://processing.org/reference/StringList.html
byte[]
now.int[]
orchar[]
, etc., just a matter of replacing thosebyte[]
declarations w/ it.for ()
towhile ()
. Check it out!GoToLoops I dont quite understand this piece of code that you coded can you explain it to me?
Actually I dunno whether your doubts are related to StringBuilder class or the algorithm itself! :-/
You can read about StringBuilder class below:
https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html
StringBuilder was chosen for performance reasons.
Regular String w/ the
+
concatenator operator yield the same results:http://processing.org/reference/addition.html
Simpler String w/
+=
concatenation version:Compare the above w/ the original StringBuilder version here:
If it's something else, please point where it is so I can explain it! :-bd