Solved

# Casting a Vector

Posted on 2004-11-16
Medium Priority
326 Views
I have the following code:

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

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
Question by:thanassis
• 5

LVL 86

Expert Comment

ID: 12599162
You need to print the values

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

LVL 86

Expert Comment

ID: 12599168
Sorry

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

LVL 92

Accepted Solution

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

LVL 86

Expert Comment

ID: 12599178
Or if you have 1.5

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

LVL 86

Expert Comment

ID: 12599180
Or if you have 1.5

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

LVL 86

Expert Comment

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

## Featured Post

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