1	//  File:  V2A - Copy Points from a Vector into a pair of arrays

     2	import java.util.Vector;
     3	import java.awt.Point;

     4	public class V2A {

     5	    // This method takes the info out of vector v and
     6	    // loads up two arrays, xCoords and yCoords
     7	    private void vector2Arrays(Vector<Point> v) {
     8	        xCoords = new int[v.size()];
     9	        yCoords = new int[v.size()];
    10	        for (int i = 0; i < v.size(); i++) {
    11	            Point p = /*(Point)*/ v.elementAt(i);    // Don't need to cast!
    12	            xCoords[i] = p.x;
    13	            yCoords[i] = p.y;
    14	        }
    15	    }

    16	    // Just show the contents of an array
    17	    private void dumpArray(int[] a) {
    18	        for (int i = 0; i < a.length; i++)
    19	            System.out.print(" " + a[i]);
    20	        System.out.println();
    21	    }

    22	    // Body of the program...
    23	    V2A() {
    24	        System.out.println("This is V2A...");
    25	        v = new Vector<Point>();
    26	        for (int i = 0; i < 7; i++) {
    27	            Point p = new Point(i, i);
    28	            v.addElement(p);
    29	        }
    30	        System.out.println("v = " + v);
    31	        vector2Arrays(v);
    32	        System.out.print("x = ");
    33	        dumpArray(xCoords);
    34	        System.out.print("y = ");
    35	        dumpArray(yCoords);
    36	    }

    37	    public static void main(String[] args) {
    38	        System.out.println("Vector-to-Arrays\n");
    39	        new V2A();
    40	    }

    41	    private Vector<Point> v;           // points in the polyline
    42	    private int[] xCoords;
    43	    private int[] yCoords;
    44	}

    45	/* ----- Output from this program -----

    46	Vector-to-Arrays

    47	This is V2A...
    48	v = [java.awt.Point[x=0,y=0], java.awt.Point[x=1,y=1],
    49	     java.awt.Point[x=2,y=2], java.awt.Point[x=3,y=3],
    50	     java.awt.Point[x=4,y=4], java.awt.Point[x=5,y=5],
    51	     java.awt.Point[x=6,y=6]]
    52	x =  0 1 2 3 4 5 6
    53	y =  0 1 2 3 4 5 6

    54	----- End of Output ----- */