copy multi dim array to Vector and print, goofy output

I thought it would print the contents of the array, such as Paper, Large or Plastic, Small. Instead I got this. Can anyone lead me in the right direction?

Also, why is it that when I put the print statement for the vector in the printVectorList method it does not recognize cupVector?

output: Vector contents

[[[I@10b62c9]

BUILD SUCCESSFUL (total time: 0 seconds)

/*

* Main.java

*

* Created on May 21, 2007, 12:41 PM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

/**

*

* @author P

*/

import java.util.Vector;

publicclass Main{

/* The main method in the Main class will instantiate an array of 10 Cup

objects. Five cups will be

small and plastic. The other five will be large and paper.

From the array, you will use a for loop to copy the Array of Cups into a

Vector, an ArrayList,

and a LinkedList. Note: The Vector, ArrayList, and LinkedList should all be

static instance variables so that they

can be used by other static methods than just the main method.

For example,

int cups[] = new Cup[10]//added by DS in lab

//the initialization

for(int i=0; i<cups.length; i++){

*///copy a cup into the Vector

//copy a cup into the ArrayList

//copy a cup into the LinkedList

//After the population of these data structures, print the cup information in

//each by calling

//appropriate print methods from main, for example:

//printCupVector(), printCupArrayList(), and printCupLinkedList().*/

privatestaticvoid printCupVector()

{

System.out.println("Vector contents");

}

privatestaticvoid printCupArrayList()

{

}

privatestaticvoid printCupLinkedList()

{

}

//This means that you have to create these three private methods in Main.java.

//Declare them as

//static so that the main method can call them without having to instantiate a

//class.

//Post your code and output from running it to the Discussion Board and comment

//on other

//postings. Be sure that you get your code to run on your own before looking at

//another student's

//posting. You will be graded on the quality of your postings: good clean

//indentation, good naming

//of variables, methods, classes, and so forth.

publicstaticvoid main(String[] args)

//1. create an array of ten cups as specified above. 5 small and 5 large

//

//2. Define the private static variables for Vector ArrayList and LinkList

//3. Copy the contents of the array of cups into the Vector ArrayList and LinkList

{

int cups[][] ={{0,0},{0, 0},{0,0},

{0,0},{0,0},{1,1},{1,1},

{1,1},{1,1},{1,1}};

//int cups[] = new Cup[10];

Vector cupVector =new Vector();

for(int i=0; i><cups.length; i++);

cupVector.add(cups);

printCupVector();

System.out.println(cupVector.toString() );

//copy a cup into the Vector

//copy a cup into the ArrayList

//copy a cup into the LinkedList

}

/* Main.java will contain a class Main.

/** Creates a new instance of Main */

}

/*

* Cup.java

*

* Created on May 21, 2007, 12:41 PM

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

/**

*

* @author P

*/

publicclass Cup{

//Define the class Cup with the instance variables:

private String cupSize;//cupSize will be set to "small" or "large" for

//ounces in the constructor

private String cupMaterial;// will be set to "plastic" or "paper" in the

//constructor

privateint sizeCode;

privateint materialCode;

publicstaticfinalint LARGE = 1;

publicstaticfinalint SMALL = 0;

publicstaticfinalint PAPER = 1;

publicstaticfinalint PLASTIC = 0;

//The Cup constructor will be coded in the following way. Copy and paste this

//code into your Cup class.

//public Cup(String cupSize, String cupMaterial){

// this. cupSize = cupSize;

// this.cupMaterial = cupMaterial;

// if(cupSize.equals("large"))

//sizeCode = LARGE;

// else

//sizeCode = SMALL;

/** Creates a new instance of Cup */

public Cup(String cupSize, String cupMaterial){

this. cupSize = cupSize;

this.cupMaterial = cupMaterial;

if(cupSize.equals("large"))

sizeCode = LARGE;

else

sizeCode = SMALL;

if(cupMaterial.equals("paper"))

materialCode = PAPER;

else materialCode = PLASTIC;

}

//

}

>

[9013 byte] By [pberardi1a] at [2007-11-27 5:09:40]
# 1

All you're doing is adding an array to the first position of a Vector. You're not converting the array structure to a vector structure in any way.

The vector is printing the first "[" and the last "]" in the output you're seeing. What's in between them is what an array returns as its toString method.

To do what you seem to want to do, you should first either create the data structures directly as java.util.List objects (Vector is one, but there are others), or alternatively, you can turn the arrays structure into a structure of Lists by creating a vector of vectors, and adding each inner array in cups[][] to a new Vector object. I'd suggest the former.

After you do that, you'll have more to do. You'll have to provide a meaningful toString method for your Cup object; otherwise you'll just get more of the same kind of output you're getting now.

paulcwa at 2007-7-12 10:29:33 > top of Java-index,Java Essentials,New To Java...
# 2
I just want to copy the array's contents to the Vector and then print the output
pberardi1a at 2007-7-12 10:29:33 > top of Java-index,Java Essentials,New To Java...
# 3

int cups[][] = {{0,0}, {0, 0}, {0,0},

{0,0}, {0,0},{1,1}, {1,1},

{1,1}, {1,1}, {1,1}};

Vector cupVector = new Vector();

for(int i=0; i><cups.length; i++);// don't put a semicolon here, it makes the loop useless

cupVector.add(cups); // don't add the whole array to the vector, add a single element, ie cups[x][y]

// you'll need two loops, one for the first dimension of the array, and another for the second dimension.

>

hunter9000a at 2007-7-12 10:29:33 > top of Java-index,Java Essentials,New To Java...