8 Replies Latest reply: May 22, 2013 10:19 AM by aksarben RSS

    adding  different  data types to collection & how to retrive ?

    1008567
      Hi all,

      public static void main(String[] args) {
                          
                          
                ArrayList ar = new ArrayList();
                ar.add("Sting1");
                ar.add(12);
                ar.add(15.4);
                
                Iterator it = ar.iterator();
                while(it.hasNext()){
                     String s =(String)it.next();
                
                     System.out.println("vlaues are :::"+s);
                }
                     }
      ============================================
      Here I am getting Exception:
      Exception in thread "main" vlaues are :::Sting1
      java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
           at collections.VectorDemo.main(VectorDemo.java:18)