-2

I have a Array list.I want to convert this into separate array. My Array list name is [obj];

obj={{[A],[B]} , {[C],[D]}, {[E],[F]}  }

> Now I want to convert  it to separate Array. array x1= {[A],[B]};
> array x2= {[C],[D]}; array x3=  {[E],[F]};

 What am tried:

    for (var i = 0; i < obj.length; i++) {  
    X = obj[i];  
    } 

Don't know how to solve this.Suggest some ideas.

monica
  • 91
  • 3
  • 12

2 Answers2

0

Object[] objArray = obj.toArray(new Object[obj.size()]);

Abhay
  • 1
-1

You have not provided much details of what you actually need. But from the sample code you provided I assume this is what you are trying to achieve. To understand clearly Instead of object I used a class Holder with a single String to store the letter.

I have used Lambda expression to print the list

public class TestMain2 {

public static void main(String[] args) {

    Holder a = new Holder("A");
    Holder b = new Holder("B");

    Holder c = new Holder("C");
    Holder d = new Holder("D");

    Holder e = new Holder("E");
    Holder f = new Holder("F");

    Holder[] childHolder1 = { a, b };
    Holder[] childHolder2 = { c, d };
    Holder[] childHolder3 = { e, f };

    List<Holder[]> holderParentList = new ArrayList<Holder[]>();

    holderParentList.add(childHolder1);
    holderParentList.add(childHolder2);
    holderParentList.add(childHolder3);

    holderParentList.forEach( child->{
        System.out.println(child[0]+","+child[1]);

    });


}

}

class Holder {

private String a;

public Holder(String a) {
    super();
    this.a = a;
}

public String getA() {
    return a;
}

public void setA(String a) {
    this.a = a;
}

@Override
public String toString() {
    return a;
}

}

Tomz
  • 85
  • 5