Why does my program return the error "ArrayIndex Out Of Bounds Exception: 4"?

my code generates a gene, this gene consists of two different things, inputs “i” and outputs “o”. they have 2 inputs and 2 outputs it and the parts are seperated by a "1 then cuts this gene into multiple pieces, so the first input will be genpart[0] and the first output will be genpart[1], what I am trying to achieve in the moment is having it do this for every gene, since it generates 51 of them. but i cannot figure out how to do this, as appareantly it changes the array length when you do this once. how do I make it work?