SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Tom Silverman: SCJP5, SCJD6, SCWCD5, SCBCD5, IBM-142, ScrumMaster
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Paul Beckett wrote:if you want to change a List<Integer> into an Integer[] you can try the Collection.toArray(T[]) method. This uses generics so is java1.5 and later only.
Have a look at the javadoc for this to understand its behaviour - it may not be exactly what you need (ie it does not give you an array of primitives).
However, I'd probably approach this problem by creating the array manually and then iterating over the list to populate the array.
Harshana Dias wrote:
Just try following and still showing Type mismatch: cannot convert from Object[] to String[]. Shouldn't generics recognized and make a String array..
Campbell Ritchie wrote:How can a zero-length array not be empty? The memory use will be minimal.
Mike Jensen wrote:I like to use the IntArrayList from Colt. (http://acs.lbl.gov/~hoschek/colt/)
Colt provides a set of Open Source Libraries for High Performance Scientific and Technical Computing in Java.
Api for the IntArrayList is: http://acs.lbl.gov/~hoschek/colt/api/cern/colt/list/IntArrayList.html
The Colt library has more goodies than this, check it out
Consider Paul's rocket mass heater. |