Search code examples
javaarraylistcomparable

converting java ArrayList<Comparable> to Comparable[]


I am trying to get some Comparable elements into a collection and return it as a Comparable[].

public Comparable[] getPerms() {
    ArrayList<Comparable> resList = new ArrayList<Comparable>();
    while(hasNext()) {
       for (int i=0; i<r; i++) {
         resList.add(index[i]);
       }
       moveIndex();
    }
    Comparable[] resultArray ;//how convert resList into array
    return resultArray;
  }

However ,I am not sure how to get the ArrayList<Comparable> as a Comparable[]

Any help appreciated.


Solution

  • resList.toArray(new Comparable[resList.size()])