System.arraycopy() any clue?
in
Programming Questions
•
1 year ago
hello to all
I'm passing an array(char[][]) into a method. I'm using the arraycopy() to make a copy of the array and avoid modify the array outside of the class. but I can't get it.
please any help will be amazing.
thanks in advance
C.
- public char[][] GenrMutation(char[][] pop, float ChroPercent)
- {
- SelectChromosomes(pop);
- int chroCant = (int)(pop[0].length * ChroPercent);
- if(chroCant == 0){ chroCant = 1;}
- char[][] mutatedPop = new char[pop.length][];
- System.arraycopy(pop, 0, mutatedPop, 0, pop.length);
- char rndChar; //random Character to replace
- int pointer; //random pointer, for the index
- for(int i = 0; i < cant; ++i) //the loop for the pop
- {
- for(int j = 0; j < chroCant; ++j) //the loop for the chro
- {
- rndChar = RandomChar();
- pointer = new Random().nextInt(mutatedPop[i].length);
- mutatedPop[arrIndex[i]][pointer] = rndChar;
- }
- }
- return mutatedPop;
- }
and in the main, this is how I'm calling the function.
also I tryed using the clone() function. but it did not work.
-
import processing.core.*;
public class Main {
static PApplet mirrorApplet;public static void main(String[] args){char[][] myCharPop;@SuppressWarnings("unused")char[][] mutatedPop;MGenrPopulation charPop = new MGenrPopulation();myCharPop = charPop.CharPopulation(5, 10);MMutation mutation = new MMutation(mirrorApplet, (float)0.4);mutatedPop = mutation.GenrMutation(myCharPop, (float)0.3);}
}
1