Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String[] words = wordBag.toArray();
- String[] dict = dictBag.toArray();
- Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
- // public <T> T[] toArray() //OK
- public T[] toArray() //OK
- {
- // the cast is safe because the new array contains null entries
- @SuppressWarnings("unchecked")
- T[] result = (T[])new Object[numberOfEntries]; // unchecked cast
- for (int index = 0; index < numberOfEntries; index++)
- {
- result[index] = bag[index];
- } // end for
- return result;
- } // end toArray
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement