Abdul Ahmad Abdul Ahmad - 7 months ago 18
Java Question

giving an arraylist the value of another arraylist JAVA

adding a different type array list to each other.

Answer

Well instead of making an instance of banana in apple why dont you make an instance of apple in banana and just do this:

Apple apple = new Apple();
bananaArrayList = apple.appleArrayList;

So since it is created inside a function you initialize it in the constructor like so:

public class Apple{
public ArrayList<Perk> appleArrayList;

public PerkGenerator() {
        this.appleArrayList = new ArrayList();

And if you do that, there is no need to do it inside a function. But if you still want to do it inside a function. Just keep that code. And do this inside apple:

public ArrayList makeApple(){
    ArrayList apples = new ArrayList();
    return apples;

And then inside of banana you do this:

bananaArrayList = apple.makeApple

This works, because the make apple function returns an arraylist :) Here is some info on returning values from methods :) http://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html

Hope i could help :)