Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector of vector...

 
lokesh rajarathnam
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why aren't you using a String[][]?

As Paul has suggested, ArrayList<String> and ArrayList<ArrayList<String>> are better implementations.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic