Reputation: 967
I have created two class in Java. The main class 'Main' is used to pass array values into the second class 'Plan'. My code looks something like this:
import java.util.ArrayList;
import java.utils.Arras;
public class Main {
public enum State {
A,
D,
H
};
Plan[] plan= new Plan[] {
new Plan(new State[]{State.A, State.A, State.A}),
new Plan(new State[]{State.A, State.D, State.H})};
}
My other class 'Plan' looks like this:
import java.utils.Arrays;
public class Plan {
public static Main.State[] input;
public static Main.State[] output;
public static Main.State[] input_new = new Main.State[4];
this.input = input;
this.output = output;
this.input_new = input_new;
for(int i = 0; i < input.length; i++) {
input_new[i] = input[i];
}
}
Now at the end of the loop I want to append the arrays so that it prints a single array which is
A A A A D H.
I tried using [this]/How can I concatenate two arrays in Java?) method, but it gives me an eeror saying 'ArrayUtils' cannot be resolved. Can somebody kindly point out my mistake here?
Thank you in advance.
Upvotes: 0
Views: 116
Reputation:
Like the answer you are relating to states, ArrayUtils is a class of the Apache Commons library. You can either add the dependency to your project, or use one of the manual approaches which are also posted in the same thread than the answer that you used.
Upvotes: 1
Reputation: 14383
The class ArrayUtils
belongs to Apache Commons Lang library. Follow the link to get the jar and include in your classpath.
Upvotes: 1
Reputation: 1641
Add the Apache Commons Dependency? ArrayUtils
is not part of the JDK.
How you do this depends on your build tooling. Please Google how you add JAR dependencies to the tooling you are using.
Upvotes: 1
Reputation: 425358
Try this:
Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2)).toArray();
Upvotes: 1