Example usage for java.util Vector toArray

List of usage examples for java.util Vector toArray

Introduction

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

Prototype

public synchronized Object[] toArray() 

Source Link

Document

Returns an array containing all of the elements in this Vector in the correct order.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    Vector v1 = new Vector();
    v1.add("A");/*from   www. ja v  a  2  s .  co m*/
    v1.add("B");
    v1.add("C");
    Object[] array = v1.toArray();

    for (int i = 0; i < array.length; i++) {
        System.out.println(array[i]);
    }
}

From source file:Main.java

public static void main(String args[]) {
    Vector<String> v1 = new Vector<String>();
    v1.add("A");/*ww  w. j  a  v  a  2  s .c om*/
    v1.add("B");
    v1.add("C");
    Object[] array = v1.toArray();

    for (int i = 0; i < array.length; i++) {
        System.out.println(array[i]);
    }
}

From source file:gda.util.PackageMaker.java

/**
 * @param args//from  ww w  .j  a v  a 2 s .  co m
 */
public static void main(String args[]) {
    String destDir = null;
    if (args.length == 0)
        return;
    String filename = args[0];
    if (args.length > 1)
        destDir = args[1];
    try {
        ClassParser cp = new ClassParser(filename);
        JavaClass classfile = cp.parse();
        String packageName = classfile.getPackageName();
        String apackageName = packageName.replace(".", File.separator);
        if (destDir != null)
            destDir = destDir + File.separator + apackageName;
        else
            destDir = apackageName;
        File destFile = new File(destDir);
        File existFile = new File(filename);
        File parentDir = new File(existFile.getAbsolutePath().substring(0,
                existFile.getAbsolutePath().lastIndexOf(File.separator)));
        String allFiles[] = parentDir.list();
        Vector<String> selectedFiles = new Vector<String>();
        String toMatch = existFile.getName().substring(0, existFile.getName().lastIndexOf("."));
        for (int i = 0; i < allFiles.length; i++) {
            if (allFiles[i].startsWith(toMatch + "$"))
                selectedFiles.add(allFiles[i]);
        }
        FileUtils.copyFileToDirectory(existFile, destFile);
        Object[] filestoCopy = selectedFiles.toArray();
        for (int i = 0; i < filestoCopy.length; i++) {
            FileUtils.copyFileToDirectory(new File((String) filestoCopy[i]), destFile);
        }
    }

    catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Parses the vector to array.//ww w . j  ava  2  s .c  o  m
 * @param vector the instance of Vector
 * @return the array
 */
public static Object[] parseArray(Vector vector) {
    return vector.toArray();
}

From source file:Main.java

public static Object[][] to2DArray(Vector<Vector> towDVector) {
    Object[][] towDArray = new Object[towDVector.size()][];
    for (int i = 0; i < towDVector.size(); i++) {
        Vector row = (Vector) towDVector.elementAt(i);

        towDArray[i] = row.toArray();
    }/* w  w  w .j a  v  a 2  s.c  om*/
    return towDArray;
}

From source file:modnlp.capte.AlignerUtils.java

public static String removeLongWhiteSpace(String s) {
    s = s.trim();/*ww  w  . ja  va  2 s  .com*/
    while (s.contains("  ")) // two white spaces
    {
        s = s.replaceAll("  ", " "); // the first arg should contain 2 spaces, the second only 1
    }
    //System.out.println("Length before UTF8 cleaning " + s.length());
    CharsetDecoder utf8Decoder = Charset.forName("UTF-8").newDecoder();
    utf8Decoder.onMalformedInput(CodingErrorAction.IGNORE);
    utf8Decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
    try {
        ByteBuffer bytes;
        bytes = ByteBuffer.wrap(s.getBytes());
        CharBuffer parsed = utf8Decoder.decode(bytes);
        s = parsed.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    //This code removes all of the bytes with value of zero
    // Gerard 21st March 2012: Solved, bug with random spaces in segments
    byte[] b = s.getBytes();
    Vector<Byte> vb = new Vector();

    for (int i = 0; i < b.length; i++) {
        if (b[i] != 0) {
            vb.add(b[i]);
        }
    }
    Object[] ba = vb.toArray();
    Byte[] bya = new Byte[ba.length];
    byte[] byta = new byte[ba.length];
    for (int i = 0; i < ba.length; i++) {
        bya[i] = (Byte) ba[i];
        byta[i] = bya[i].byteValue();
    }
    s = new String(byta);
    return s;
}

From source file:peakmlviewer.widgets.IPeakIntensityGraph.java

public void setPeaks(Vector<Header> headers, Vector<IPeak> peaks) {
    setPeaks((Header[]) headers.toArray(), (IPeak[]) peaks.toArray());
}

From source file:TreeViewBasedOnNode.java

public Object[] getChildren(Object parentElement) {
    Vector subcats = ((Node) parentElement).getSubCategories();
    return subcats == null ? new Object[0] : subcats.toArray();
}

From source file:SampleListViewer.java

private void init() {
    languages.add(new Language("Java", true));
    languages.add(new Language("C", false));
    languages.add(new Language("C++", true));
    languages.add(new Language("SmallTalk", true));

    listViewer = new ListViewer(shell);

    listViewer.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            Vector v = (Vector) inputElement;
            return v.toArray();
        }//from  w w w  . j  av  a2s  .co  m

        public void dispose() {
            System.out.println("Disposing ...");
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            System.out.println("Input changed: old=" + oldInput + ", new=" + newInput);
        }
    });

    //listViewer.setContentProvider(new ArrayContentProvider());

    listViewer.setInput(languages);

    listViewer.setLabelProvider(new LabelProvider() {
        public Image getImage(Object element) {
            return null;
        }

        public String getText(Object element) {
            return ((Language) element).genre;
        }
    });

    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            StringBuffer sb = new StringBuffer("Selection - ");
            sb.append("tatal " + selection.size() + " items selected: ");
            for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
                sb.append(iterator.next() + ", ");
            }
            System.out.println(sb);
        }
    });

    listViewer.addFilter(new ViewerFilter() {
        public boolean select(Viewer viewer, Object parentElement, Object element) {

            if (((Language) element).isObjectOriented)
                return true;
            else
                return false;
        }
    });

    listViewer.setSorter(new ViewerSorter() {
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((Language) e1).genre.compareTo(((Language) e2).genre);
        }

    });

    //      Object[] toBeSelectedItems = new Object[2];
    //      toBeSelectedItems[0] = languages.elementAt(languages.size()-1);
    //      toBeSelectedItems[1] = languages.elementAt(languages.size()-2);
    //      IStructuredSelection selection = new StructuredSelection(toBeSelectedItems);
    //      
    //      listViewer.setSelection(selection);

    //      
    //      Vector v = new Vector();
    //      v.addElement(new Language("VB", true));
    //      
    //      listViewer.setInput(v);
    //      
    //      listViewer.add(new Language("C#", true));
}

From source file:org.photovault.swingui.folderpane.FolderController.java

/**
 Expand the paths to those folders that have photos in model
 *//*from w  w  w .j  av a2 s  .co m*/
private void expandTreePaths() {
    for (PhotoFolder folder : expandedFolders) {
        Vector parents = new Vector();
        // parents.add( nodeMapper.mapFolderToNode( folder ) );
        while ((folder = folder.getParentFolder()) != null) {
            parents.add(0, nodeMapper.mapFolderToNode(folder));
        }
        if (parents.size() > 0) {
            TreePath path = new TreePath(parents.toArray());
            Iterator viewIter = views.iterator();
            while (viewIter.hasNext()) {
                PhotoSelectionView view = (PhotoSelectionView) viewIter.next();
                view.expandFolderTreePath(path);
            }
        }
    }
}