Example usage for java.util List toArray

List of usage examples for java.util List toArray

Introduction

In this page you can find the example usage for java.util List toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    String[] a = new String[] { "a", "c", "b" };

    List l = (Arrays.asList());
    String stuff[] = (String[]) l.toArray(new String[0]);
}

From source file:Main.java

public static void main(String[] argv) {
    JTextPane textPane = new JTextPane();

    List list = new ArrayList();

    TabStop[] tstops = (TabStop[]) list.toArray(new TabStop[0]);
    TabSet tabs = new TabSet(tstops);

    Style style = textPane.getLogicalStyle();
    StyleConstants.setTabSet(style, tabs);
    textPane.setLogicalStyle(style);/*from w  ww  . ja  va2  s  .  c om*/
}

From source file:Main.java

public static void main(String[] args) {

    List<String> theList = new LinkedList<String>();
    theList.add("A");
    theList.add("B");
    theList.add("C");
    theList.add("D");

    String[] my = theList.toArray(new String[theList.size()]);

    for (int i = 0; i < my.length; i++) {
        System.out.println(my[i]);
    }//from  w  w w . ja v  a 2s.  c o  m
}

From source file:Main.java

public static void main(String[] args) {

    List<String> theList = new LinkedList<String>();
    theList.add("A");
    theList.add("B");
    theList.add("C");
    theList.add("D");

    String[] my = theList.toArray(new String[0]);

    for (int i = 0; i < my.length; i++) {
        System.out.println(my[i]);
    }//from   w w  w .j  a  va  2s. c  o m
}

From source file:Main.java

public static void main(String[] args) {
    List<String> carList = new ArrayList<String>();

    carList.add("A");
    carList.add("B");
    carList.add("C");
    carList.add("D");

    String[] carArray = carList.toArray(new String[0]);

    for (String car : carArray) {
        System.out.println(car);//  ww  w  . j ava 2  s.co  m
    }
}

From source file:Main.java

public static void main(String[] args) {

    List<String> carList = new ArrayList<String>();

    carList.add("A");
    carList.add("B");
    carList.add("C");
    carList.add("D");

    String[] carArray = carList.toArray(new String[0]);

    for (String car : carArray) {
        System.out.println(car);/*from w  w w . j a v a 2  s .  co  m*/
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new LinkedList<String>();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    String[] colors = new String[list.size()];
    list.toArray(colors);

    for (int i = 0; i < colors.length; i++) {
        System.out.println("color = " + colors[i]);
    }//from  w w w  .  jav  a  2  s  .c  om
}

From source file:Main.java

public static void main(String[] args) throws FileNotFoundException {
    List<Integer> arraySource = new ArrayList<>();
    for (int i = 0; i < 99999; i++) {
        arraySource.add(i);/*from w w w  .j  av a 2s.c  o  m*/
    }

    Integer[] myArray = new Integer[999];
    myArray = arraySource.toArray(myArray);
    long startTime = System.currentTimeMillis();
    Arrays.sort(myArray);
    long endTime = System.currentTimeMillis();
    System.out.println("Time take in serial: " + (endTime - startTime) / 1000.0);

    Integer[] myArray2 = new Integer[999];
    myArray2 = arraySource.toArray(myArray);
    startTime = System.currentTimeMillis();
    Arrays.parallelSort(myArray2);
    endTime = System.currentTimeMillis();
    System.out.println("Time take in parallel: " + (endTime - startTime) / 1000.0);

}

From source file:SafeListCopy.java

public static void main(String[] args) {
    List wordList = Collections.synchronizedList(new ArrayList());

    wordList.add("Synchronization");
    wordList.add("is");
    wordList.add("important");

    String[] wordA = (String[]) wordList.toArray(new String[0]);

    printWords(wordA);/*  ww w .  java 2 s . c  o m*/

    String[] wordB;
    synchronized (wordList) {
        int size = wordList.size();
        wordB = new String[size];
        wordList.toArray(wordB);
    }

    printWords(wordB);

    // Third technique (the 'synchronized' *is* necessary)
    String[] wordC;
    synchronized (wordList) {
        wordC = (String[]) wordList.toArray(new String[wordList.size()]);
    }

    printWords(wordC);
}

From source file:com.ibm.ie.tachyon.fuse.TachyonFuse.java

public static void main(String[] args) {
    final TachyonFuseOptions opts = parseOptions(args);
    if (opts == null) {
        System.exit(1);/*from  w  w  w .j a  v  a  2  s.  co  m*/
    }
    final TachyonFuseFs fs = new TachyonFuseFs(opts);
    final List<String> fuseOpts = opts.getFuseOpts();
    fuseOpts.add("-odirect_io");

    try {
        fs.mount(Paths.get(opts.getMountPoint()), true, opts.isDebug(), fuseOpts.toArray(new String[0]));
    } finally {
        fs.umount();

    }
}