The Artima Developer Community
Sponsored Link

Java Answers Forum
converting vector to array

2 replies on 1 page. Most recent reply: Mar 6, 2002 9:35 AM by Bill Venners

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
jayakumar perumal

Posts: 16
Nickname: jai
Registered: Feb, 2002

converting vector to array Posted: Mar 6, 2002 1:18 AM
Reply to this message Reply
Advertisement
can anyone help me how to convert a vector to integer array
thanx
jai


Alain Ravet

Posts: 19
Nickname: aravet
Registered: Feb, 2002

Re: converting vector to array Posted: Mar 6, 2002 2:29 AM
Reply to this message Reply
Vectors offer a "toArray" method.
Integers offer a "intValue" method.

        Vector vector = new Vector();
        vector.add( new Integer(1)) ;
        vector.add( new Integer(2)) ;
 
        Integer[] ints = (Integer[])vector.toArray(new Integer[vector.size()]);
 
        int[] result = new int[ints.length] ;
        for (int i = 0; i < ints.length; i++) {
            result[i] = ints[i].intValue() ;
        }
 

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: converting vector to array Posted: Mar 6, 2002 9:35 AM
Reply to this message Reply
By the way, Vector is kind of a legacy class. Since JDK 1.2 was released, I always use ArrayList not Vector where I can.

Flat View: This topic has 2 replies on 1 page
Topic: Discrete Event Simulation ( Proper Code) Previous Topic   Next Topic Topic: using Jbuttons to navigate around a Java application!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use