how to convert vector to string array in java

Java 8Object Oriented ProgrammingProgramming

Following program converts a vector into a array of String.

Example

import java.util.Vector;
public class Tester {
   public static void main(String[] args) {
      Vector<String> data = new Vector<String>();
      data.add("A");
      data.add("B");
      data.add("C");
      String[] strObjects = data.toArray(new String[data.size()]);
      for(String obj: strObjects) {
         System.out.println(obj);
      }
   }
}
raja
Published on 06-Feb-2018 15:25:03
Advertisements