Convert an ArrayList to an object array

后端 未结 6 1117
情深已故
情深已故 2020-12-13 09:20

Is there a command in java for conversion of an ArrayList into a object array. I know how to do this copying each object from the arrayList into the object array, but I was

6条回答
  •  悲哀的现实
    2020-12-13 09:45

    You can use this code

    ArrayList a = new ArrayList();
    Object[] o = a.toArray();
    

    Then if you want that to get that object back into TypeA just check it with instanceOf method.

提交回复
热议问题