I am a beginner at Java. I have created a main program with the main class . This is called Main.java
. THis main class contains a set of arrays. These arrays are imported into the second class called the Test.java
. Now I am looking for a method to concatenate all the arrays at the end of this second class. My code looks as shown below:
import java.util.Arrays;
public class Main{
public enum State{A,D,H};
Test[] tests = new Test[]{
new Test(new State[]{State.A, State.H, State.A, State.H}),
new Test(new State[]{State.A, State.H, State.A, State.D}),
new Test(new State[]{State.H, State.D, State.A, State.A})
};
The calss Test.java looks like this :
import java.util.Arrays;
public class Test{
public static Main.State[] in;
public static Main.State[] in_state= new Main.State[4];
public static String data_in;
Test(Main.State[] in){
this in = in;
this.in_state=in_state;
for( int i=0; i<in.length; i++){
in_state[i]=in[i];
data_in =java.util.Arrays.toString(in_state);
data_in = data_in.replaceAll(",", "");
data_in = data_in.replaceAll(" ","");}
System.out.println( "The input arrays are" +data_in) ;
Now the output I get looks like this :
The input arrays are[AHAH]
The input arrays are[AHAD]
The input arrays are[HDAA]
Instead of this I want to get it as AHAHAHADHDAA. I tried using the ArrayUtils.addAll
function but the program stops executing abruptly. Could somebody please help me out.
Thank you in advance.