C# Equivalent to java.utl.Vector

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Egghead

    C# Equivalent to java.utl.Vector

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

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


    thanks
    Egghead


  • Jon Skeet [C# MVP]

    #2
    Re: C# Equivalent to java.utl.Vector

    Egghead <robertlo_NO_SP AM@shaw.ca> wrote:[color=blue]
    > Does anyone know if there is any C#'s class equivalent to java.utl.Vector ?
    > I think the System.Collecti ons.ArrayList is not the same:[/color]

    It is, pretty much.
    [color=blue]
    > In java:
    > for(int i = 0; i<myVector.leng th;i++)
    > {
    > mySecondVector = (Vector)MyVecto r[i]// <--- in C#, it does not allow me
    > to add an ArrayList inside an ArrayList, may be I miss something :([/color]

    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.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • MarkT [developmentor]

      #3
      Re: C# Equivalent to java.utl.Vector

      > > I think the System.Collecti ons.ArrayList is not the same:[color=blue]
      >
      > It is, pretty much.[/color]

      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.Vecto r is the old,
      synchronized list while java.util.Array List 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.Array List. The two reasons
      I know of to use java.util.Vecto r are if you want the synchronization or you
      need to run on a pre 1.2 version of the jre.

      Comment

      • Feng Chun

        #4
        Re: C# Equivalent to java.utl.Vector

        This is helpful

        "Jon Skeet [C# MVP]" wrote:
        [color=blue]
        > Egghead <robertlo_NO_SP AM@shaw.ca> wrote:[color=green]
        > > Does anyone know if there is any C#'s class equivalent to java.utl.Vector ?
        > > I think the System.Collecti ons.ArrayList is not the same:[/color]
        >
        > It is, pretty much.
        >[color=green]
        > > In java:
        > > for(int i = 0; i<myVector.leng th;i++)
        > > {
        > > mySecondVector = (Vector)MyVecto r[i]// <--- in C#, it does not allow me
        > > to add an ArrayList inside an ArrayList, may be I miss something :([/color]
        >
        > 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.
        >
        > --
        > Jon Skeet - <skeet@pobox.co m>
        > http://www.pobox.com/~skeet
        > If replying to the group, please do not mail me too
        >[/color]

        Comment

        • Bjorn Abelli

          #5
          Re: C# Equivalent to java.utl.Vector

          "Egghead" wrote...
          [color=blue]
          > Anyway, I attach an app that show it is not the same.[/color]

          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...
          [color=blue]
          > It does not work at the line where I withdraw
          > the arraylist from the array list.[/color]

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

          resultString.Ad dRange(RowStrin g);

          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.Ad d(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


          Comment

          • EggHead

            #6
            Re: C# Equivalent to java.utl.Vector

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



            "Bjorn Abelli" <bjorn_abelli@D oNotSpam.hotmai l.com> wrote in message
            news:%23mQgUehU FHA.4092@TK2MSF TNGP12.phx.gbl. ..[color=blue]
            > "Egghead" wrote...
            >[color=green]
            >> Anyway, I attach an app that show it is not the same.[/color]
            >
            > 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...
            >[color=green]
            >> It does not work at the line where I withdraw
            >> the arraylist from the array list.[/color]
            >
            > That's because you didn't add the ArrayList as an ArrayList in the first
            > place...
            >
            > resultString.Ad dRange(RowStrin g);
            >
            > 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.Ad d(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
            >
            >[/color]


            Comment

            Working...