Hallo alle,
ich benutze gerade FastBitSet von Javolution-collections. Bei FastBietSet gibt es eine Funktion: toArray()
FastBitSet ist ähnlich wie BitSet.
Ich möchte jetzt einem Integer[ ] den Inhalt von dem FastBitSet übergeben:
aber diese Code ist falsch, die Fehlermeldung ist : Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
Wie kann ich die toArray() richtig benutzen? Kann jemand mir mal helfen?
Vielen Dank!
______________________
Die JavaDoc von FastBitSet ist:
toArray
public Object[] toArray()
Returns a new array allocated on the heap containing all of the values in this collection in proper sequence.
Note: To avoid heap allocation toArray(Object[]) is recommended.
Specified by:
toArray in interface Collection<E>
Returns:
toArray(new Object[size()])
---------------------------------------------------
toArray
public <T> T[] toArray(T[] array)
Fills the specified array with the values of this collection in the proper sequence.
Note: Unlike standard Collection, this method does not try to resize the array using reflection (which might not be supported) if the array is too small. UnsupportedOperationException is raised if the specified array is too small for this collection.
Specified by:
toArray in interface Collection<E>
Parameters:
array - the array into which the values of this collection are to be stored.
Returns:
the specified array.
Throws:
UnsupportedOperationException - if array.length < size()
ich benutze gerade FastBitSet von Javolution-collections. Bei FastBietSet gibt es eine Funktion: toArray()
FastBitSet ist ähnlich wie BitSet.
Ich möchte jetzt einem Integer[ ] den Inhalt von dem FastBitSet übergeben:
Java:
FastBitSet fbs = new FastBitSet();
fbs.set(5);
fbs.set(7);
Integer[] abc = (Integer[])fbs.toArray();
aber diese Code ist falsch, die Fehlermeldung ist : Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
Wie kann ich die toArray() richtig benutzen? Kann jemand mir mal helfen?
Vielen Dank!
______________________
Die JavaDoc von FastBitSet ist:
toArray
public Object[] toArray()
Returns a new array allocated on the heap containing all of the values in this collection in proper sequence.
Note: To avoid heap allocation toArray(Object[]) is recommended.
Specified by:
toArray in interface Collection<E>
Returns:
toArray(new Object[size()])
---------------------------------------------------
toArray
public <T> T[] toArray(T[] array)
Fills the specified array with the values of this collection in the proper sequence.
Note: Unlike standard Collection, this method does not try to resize the array using reflection (which might not be supported) if the array is too small. UnsupportedOperationException is raised if the specified array is too small for this collection.
Specified by:
toArray in interface Collection<E>
Parameters:
array - the array into which the values of this collection are to be stored.
Returns:
the specified array.
Throws:
UnsupportedOperationException - if array.length < size()
Zuletzt bearbeitet: