Angel Sanchez Angel Sanchez - 3 months ago 12
Java Question

Copy string into array char many times

I need to copy the string into a character array the largest number of times you can within the array. In this case OPERATIVO would enter 3 times in the char array and the rest of the array could be whatever character. That I can do?

public void copyToArray( char [] arrayCharacters ){
String var = new String("OPERATIVO");

for(int i=0 ; i < 30 ; i++){


Not quite sure what you want, but I'll give it a shot:

Edit: try this one:

public static void copearCaracteres(char[] arrayOriginal )
    String cadena = new String("OPERATIVO");
    int div = arrayOriginal.length / cadena.length();
    int j = div * cadena.length();

    for(int i=0 ; i < arrayOriginal.length; i++)
        if(i == j) return;
        arrayOriginal[i] = cadena.charAt(i % cadena.length());