?
Solved

Casting a Vector

Posted on 2004-11-16
6
Medium Priority
?
326 Views
Last Modified: 2010-03-31
I have the following code:

Vector v = new Vector();
int[] test={1,3};
v.addElement(test);

If i use
System.out.println(v);
I cannot see the contents of my table!
How can i see values 1,3 of table inside from the vector?
0
Comment
Question by:thanassis
  • 5
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12599162
You need to print the values


byte[] bytes = (byte)v.get(0);
// iterate and print
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12599168
Sorry

byte[] bytes = (byte[])v.get(0);
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 12599177
Iterator i = v.iterator();
while (i.hasNext())
{
   int[] x = (int[]) i.next();
   for (int j=0; j<x.length; j++) System.out.println(x[j]+" ");
   System.out.println();
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Expert Comment

by:CEHJ
ID: 12599178
Or if you have 1.5

System.out.println(java.util.Arrays.toString((byte)v.get(0)));
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12599180
Or if you have 1.5

System.out.println(java.util.Arrays.toString((byte[])v.get(0)));
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12599203
Substitute int[] for byte[] in my previous ;-)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question