0

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.

3
  • For using arrayutils you need to have apache jar in path. Commented Jul 23, 2015 at 9:11
  • 1
    Can you put a working example. This code will not compile and we don't really know where the for loop is located in your actual code. Commented Jul 23, 2015 at 9:11
  • You might want to have a look at this commons.apache.org/proper/commons-lang/index.html Commented Jul 23, 2015 at 9:13

5 Answers 5

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@Thank you for that response. I doenload the jre and added it in my path, but I am not sure on th libraray name I should use to call it via the 'import'. Could you please tell me the lib name. Thank you :)
It should be org.apache.commons.lang.ArrayUtils. Your IDE should actually provide you with autocompletion if you just write ArrayUtils in your code and the JAR file is on the class path.
1

Try this:

Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2)).toArray();

Comments

1

The class ArrayUtils belongs to Apache Commons Lang library. Follow the link to get the jar and include in your classpath.

2 Comments

@Thank you for that response. I doenload the jre and added it in my path, but I am not sure on th libraray name I should use to call it via the 'import'. Could you please tell me the lib name. Thank you :)
import org.apache.commons.lang3.ArrayUtils;
1

Use apache.commons API for ArraysUtils

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.