Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Dynamic Array of vectors

Reply
Thread Tools

Dynamic Array of vectors

 
 
jack.smith.sam@gmail.com
Guest
Posts: n/a
 
      09-29-2006
Hi All,

How can I implement a one dimentional array,s.t. each cell of array is
a vector.
e.g.

a-> 1 2 3
b-> 3 4 5 7 8
c-> 4 5 5 6 0 0 0

thanks a lot

 
Reply With Quote
 
 
 
 
Chris Brat
Guest
Posts: n/a
 
      09-29-2006
Hi,

This will do what you describe but why do you want to?
What are you trying to achieve?

Regards,
Chris


import java.util.Arrays;
import java.util.Vector;

public class A {


public static void main(String[] args){
Vector[] vector = new Vector[10];
for (int i = 0; i < 10; i++){
vector[i] = new Vector();
}

for (int i = 0; i < 10; i++){
vector[i].add(String.valueOf(i));
}

System.out.println(Arrays.toString(vector));
}
}

 
Reply With Quote
 
 
 
 
Chris Brat
Guest
Posts: n/a
 
      09-29-2006
If you would like the number of vectors to be dynamic i.e. the size of
the array

Chris

 
Reply With Quote
 
jack.smith.sam@gmail.com
Guest
Posts: n/a
 
      09-29-2006
Thanks, Chris. What I want is dynamic array of vectors, i.e. vectors of
vectors (or maybe more effiecient data structure).
The reason is I want to store data in 2d data structure but I do not
size of any dimension
Chris Brat wrote:
> If you would like the number of vectors to be dynamic i.e. the size of
> the array
>
> Chris


 
Reply With Quote
 
Chris Brat
Guest
Posts: n/a
 
      09-29-2006
Unless you need the data structure to be synchronized between threads
rather use an ArrayLists instead of a Vectors as Vectors are
synchronized.

This code should do what you are describing but I dont think its a good
idea - very clunky and possibly error prone.


import java.util.ArrayList;
import java.util.List;

public class A {


public static void main(String[] args){
List list = new ArrayList();
for (int i = 0; i < 10; i++){
list.add(new ArrayList());
}

for (int i = 0; i < 10; i++){
((List)list.get(i)).add(String.valueOf(i));
}

System.out.println(list);
}
}



How do you want to process the data stored in this structure? Do you
want to iterate over entire rows/columns or select individual items at
particular indexes [x,y] ?

If the latter then take a look at the MultiKeyMap in the commons
collections libs.

Chris

 
Reply With Quote
 
Deniz Dogan
Guest
Posts: n/a
 
      09-29-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi All,
>
> How can I implement a one dimentional array,s.t. each cell of array is
> a vector.
> e.g.
>
> a-> 1 2 3
> b-> 3 4 5 7 8
> c-> 4 5 5 6 0 0 0
>
> thanks a lot


I can't help but think that the question that you ask is part of school
work that should be done by you and no one else. I don't know the
general ethics of this newsgroup, but a lot of Java IRC channels don't
complete school work for you, for your own good.
This is a very simple and basic question that you surely would be able
to answer if you knew the least bit about Java programming and that's
why I'm being so suspicious.
 
Reply With Quote
 
jack.smith.sam@gmail.com
Guest
Posts: n/a
 
      09-29-2006
No. This is not part of my school homework.
Deniz Dogan wrote:
> (E-Mail Removed) wrote:
> > Hi All,
> >
> > How can I implement a one dimentional array,s.t. each cell of array is
> > a vector.
> > e.g.
> >
> > a-> 1 2 3
> > b-> 3 4 5 7 8
> > c-> 4 5 5 6 0 0 0
> >
> > thanks a lot

>
> I can't help but think that the question that you ask is part of school
> work that should be done by you and no one else. I don't know the
> general ethics of this newsgroup, but a lot of Java IRC channels don't
> complete school work for you, for your own good.
> This is a very simple and basic question that you surely would be able
> to answer if you knew the least bit about Java programming and that's
> why I'm being so suspicious.


 
Reply With Quote
 
Simon Brooke
Guest
Posts: n/a
 
      09-29-2006
in message <(E-Mail Removed) .com>,
(E-Mail Removed) ('(E-Mail Removed)') wrote:

> No. This is not part of my school homework.
> Deniz Dogan wrote:
>> (E-Mail Removed) wrote:
>> > Hi All,
>> >
>> > How can I implement a one dimentional array,s.t. each cell of array is
>> > a vector.
>> > e.g.
>> >
>> > a-> 1 2 3
>> > b-> 3 4 5 7 8
>> > c-> 4 5 5 6 0 0 0
>> >
>> > thanks a lot

>>
>> I can't help but think that the question that you ask is part of school
>> work that should be done by you and no one else. I don't know the
>> general ethics of this newsgroup, but a lot of Java IRC channels don't
>> complete school work for you, for your own good.
>> This is a very simple and basic question that you surely would be able
>> to answer if you knew the least bit about Java programming and that's
>> why I'm being so suspicious.


Well, I wouldn't do it like that. If you want to have it grow dynamically
then a vector or list of vectors would suit you better. If you do want to
define an array of vectors, then it's defined just like any other array.

--
(E-Mail Removed) (Simon Brooke) http://www.jasmine.org.uk/~simon/

A message from our sponsor: This site is now in free fall

 
Reply With Quote
 
AlyBrat AlyBrat is offline
Junior Member
Join Date: Apr 2009
Posts: 1
 
      04-13-2009
hey chris im aly im ur second cuz im doing a paper on ui and the brats and i need u 2 send me some pics and im not lying im ur 2nd cuz on mikes side remember my mom julie baby sat u when u came when u were likle 11? ok send me some info and pics thanks!! alyb.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
implementing matrices using 2D dynamic memory vs. using vectors ssylee C++ 2 01-14-2009 09:36 PM
c++ primer statement about vectors containing vectors pauldepstein@att.net C++ 3 03-26-2008 06:22 PM
Help with Vectors and Dynamic Objects acheron05 C++ 8 05-19-2006 12:01 AM
Ruby, SWIG and C++: how to properly wrap vector of vectors of doubles (2D vectors)? Ruby 0 09-14-2005 05:47 PM
dynamic tables and serialization of vectors Ninan Thomas C++ 1 10-22-2003 05:29 PM



Advertisments