The Artima Developer Community
Sponsored Link

Java Answers Forum
vector() help

3 replies on 1 page. Most recent reply: Jun 12, 2003 12:14 AM by al

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 3 replies on 1 page
jayakumar perumal

Posts: 16
Nickname: jai
Registered: Feb, 2002

vector() help Posted: Mar 19, 2003 4:14 PM
Reply to this message Reply
Advertisement
hi
can someone help me how can i convert elements of a vector to a string array
thanks
jai


Rich Burgis

Posts: 17
Nickname: songbird
Registered: Mar, 2003

Re: vector() help Posted: Mar 19, 2003 6:53 PM
Reply to this message Reply
Try something like

String[ ] convert( Vector _v ) // _v contains strings or something that can
// be cast to a string
{
String[ ] array = new String[ _v.size( ) ];

for( int idx = 0; idx < _v.size( ); idx++ )
array[ idx ] = (String)_v.elementAt( idx );

return array;
}

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: vector() help Posted: Mar 19, 2003 6:55 PM
Reply to this message Reply
import java.util.* ;
 
public class Test1  {
 
	public static void main(String args[]) {
		Vector v = new Vector ( ) ;
		v.add ( "hello1" ) ;
		v.add ( "hello2" ) ;
		v.add ( "hello3" ) ;
 
		String[] s = (String[] ) v.toArray ( new String[v.size()] );
 
		int len = s.length ;
 
		for ( int i = 0 ; i < len ; i++ ) {
			System.out.println ( s[i] ) ;
		}
	}
}

al

Posts: 11
Nickname: allelopath
Registered: Jun, 2003

Re: vector() help Posted: Jun 12, 2003 12:14 AM
Reply to this message Reply
thanks for this...i googled on java convert vector to string array and this came up...just what I needed!

Flat View: This topic has 3 replies on 1 page
Topic: Log4J and NT2000 Previous Topic   Next Topic Topic: About swing set in JAVA WEB START

Sponsored Links



Google
  Web Artima.com   

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