GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Vector of vector... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector of vector..." Watch "Vector of vector..." New topic
Author

Vector of vector...

lokesh rajarathnam
Ranch Hand

Joined: May 17, 2007
Posts: 35
Hi...

I need to know how to add an vector to another vector.

Issue...
The text file contains N number of lines and each line contains 12 number of words. I need to store an 12 words(one line)in vector after that
the vector will be stored into another new vector.

I will able to do split the line into words...

any help please...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The add(E o) method will do this.

Why have you decided to use a Vector? Normally there isn't a good reason to use this class.
[ July 17, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39102
    
  23
Why aren't you using a String[][]?

As Paul has suggested, ArrayList<String> and ArrayList<ArrayList<String>> are better implementations.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Originally posted by Campbell Ritchie:
ArrayList<ArrayList<String>>

That's never a good solution. Use ArrayList<List<String>>. That can still store ArrayList<String>, but also LinkedList<String> if needed.

The declaration and initialization would be
<blockquote>code:
<pre name="code" class="core">List<List<String>> list = new ArrayList<List<String>>();
list.add(new ArrayList<String>());
</pre>
</blockquote>


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: Vector of vector...