C# Equivalent to java.utl.Vector

E

Egghead

Hi,
Does anyone know if there is any C#'s class equivalent to java.utl.Vector?
I think the System.Collections.ArrayList is not the same:

In java:
for(int i = 0; i<myVector.length;i++)
{
mySecondVector = (Vector)MyVector// <--- in C#, it does not allow me
to add an ArrayList inside an ArrayList, may be I miss something :(
for(int j = 0; j<mySecondVector.length;j++)
{
//do something
}
}


thanks
Egghead
 
J

Jon Skeet [C# MVP]

Egghead said:
Does anyone know if there is any C#'s class equivalent to java.utl.Vector?
I think the System.Collections.ArrayList is not the same:

It is, pretty much.
In java:
for(int i = 0; i<myVector.length;i++)
{
mySecondVector = (Vector)MyVector// <--- in C#, it does not allow me
to add an ArrayList inside an ArrayList, may be I miss something :(


It does, in exactly the same way as you do in Java.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
G

Guest

I think the System.Collections.ArrayList is not the same:
It is, pretty much.

I agree with Jon - I think it is pretty much the same. Certainly it is the
closest match to Vector in .NET.

My Java is getting a little rusty, but I think java.util.Vector is the old,
synchronized list while java.util.ArrayList is the new one that most people
prefer to use. When jdk 1.2 came along, Vector was retrofitted to implement
the List interface so it looks much like java.util.ArrayList. The two reasons
I know of to use java.util.Vector are if you want the synchronization or you
need to run on a pre 1.2 version of the jre.
 
G

Guest

This is helpful

Jon Skeet said:
Egghead said:
Does anyone know if there is any C#'s class equivalent to java.utl.Vector?
I think the System.Collections.ArrayList is not the same:

It is, pretty much.
In java:
for(int i = 0; i<myVector.length;i++)
{
mySecondVector = (Vector)MyVector// <--- in C#, it does not allow me
to add an ArrayList inside an ArrayList, may be I miss something :(


It does, in exactly the same way as you do in Java.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
B

Bjorn Abelli

...
Anyway, I attach an app that show it is not the same.

But as the others already said, it's *very* close, and your problem isn't
related to the small differences, but what methods you're actually using.
You would get the same problem with the corresponding method in Java's
ArrayList or Vector...
It does not work at the line where I withdraw
the arraylist from the array list.

That's because you didn't add the ArrayList as an ArrayList in the first
place...

resultString.AddRange(RowString);

AddRange adds the *elements* of RowString (which are plain strings) at the
end of the ArrayList resultString. This is similar to the "addAll" in Java's
ArrayList and Vector...

Just change the line to...

resultString.Add(RowString);

You also have a small bug in "otherList". Shouldn't...

for (int j = 0; i < RowString.Count; j++)

....rather be...

for (int j = 0; j < RowString.Count; j++)


// Bjorn A
 
E

EggHead

Thanks Bjorn,
did not c that "Add" method, must be blinded by all the VS IDE's groupies :)
Egghead
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top