2 Replies Latest reply: Feb 8, 2007 9:56 AM by 807606 RSS

    ClassCastException, from Object[] to String[]

    807606
      Hi, I want to cast an Object[] array to String[] array, I cannot figure out what is wrong with the following code... any hints please?
      HashSet<String> set = new HashSet<String>();
      set.add("one");
      set.add("two");
      
      String[] test = (String[]) set.toArray();  // Runetime error
      I got ClassCastException error at the last line. What have I done wrong?

      Thanks!