Posted by Anonymous Wed 28th Feb 2007 14:38 - Syntax is Java - 17 views
Modification of posting from Anonymous Wed 28th Feb 2007 14:18
Download | New Post | Modify | Diff | Hide line numbers
  1. import java.util.Vector;
  2.  
  3. public class vectors {
  4.  
  5.     /**
  6.      * @param args
  7.      */
  8.     public static void main([] args) {
  9.         v = new ();
  10.         v.add("TestA");
  11.         v.add("TestB");
  12.         v.add("TestC");
  13.         //does not compile without conversion
  14.         //String back = v.get(1);
  15.         back = () v.get(1);
  16.         .out.println(back);
  17.        
  18.         //does not compile
  19.         //String[] list1 = v.toArray();
  20.         //compiles, but doesnt run
  21.         //String[] list2 = (String []) v.toArray();
  22.         //this appears to work though
  23.         [] list3 = new [v.size()];
  24.         v.toArray(list3);
  25.         //and this is it on one line
  26.         [] list4 = ([]) v.toArray(new [v.size()]);
  27.        
  28.         //looping way to do it
  29.         [] list5 = new [v.size()];
  30.         for (int i = 0; i < v.size(); i++){
  31.             list5[i] = () v.get(i);
  32.         }
  33.        
  34.         //debug printouts
  35.         //for (int i = 0; i < list1.length; i++){System.out.println(list1[i]);}
  36.         //for (int i = 0; i < list2.length; i++){System.out.println(list2[i]);}
  37.         for (int i = 0; i < list3.length; i++){.out.println(list3[i]);}
  38.         for (int i = 0; i < list4.length; i++){.out.println(list4[i]);}
  39.         for (int i = 0; i < list5.length; i++){.out.println(list5[i]);}
  40.     }
  41. }

PermaLink to this entry https://pastebin.co.uk/11162
Posted by Anonymous Wed 28th Feb 2007 14:38 - Syntax is Java - 17 views
Modification of posting from Anonymous Wed 28th Feb 2007 14:18
Download | New Post | Modify | Diff | Hide line numbers

 

Comments: 0