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.

Community
  • 1
  • 1
Goldengirl
  • 957
  • 4
  • 10
  • 30
  • For using arrayutils you need to have apache jar in path. – Panther Jul 23 '15 at 09: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. – Codebender Jul 23 '15 at 09:11
  • You might want to have a look at this http://commons.apache.org/proper/commons-lang/index.html – dly Jul 23 '15 at 09:13

5 Answers5

1

Try this:

Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2)).toArray();
Bohemian
  • 412,405
  • 93
  • 575
  • 722
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.

Tobias Kremer
  • 1,531
  • 2
  • 15
  • 21
  • @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 :) – Goldengirl Jul 23 '15 at 09:39
  • 1
    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. – Tobias Kremer Jul 23 '15 at 09:44
1

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

Sharon Ben Asher
  • 13,849
  • 5
  • 33
  • 47
  • @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 :) – Goldengirl Jul 23 '15 at 09:44
  • `import org.apache.commons.lang3.ArrayUtils;` – Sharon Ben Asher Jul 23 '15 at 10:57
1

Use apache.commons API for ArraysUtils

Estimate
  • 1,421
  • 1
  • 18
  • 31
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.

Community
  • 1
  • 1
javahippie
  • 806
  • 10
  • 25