Vectors as Strings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravinttf32
    New Member
    • Sep 2007
    • 1

    Vectors as Strings

    how to pass string as vector object
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by ravinttf32
    how to pass string as vector object
    What do you mean by that?

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by ravinttf32
      how to pass string as vector object
      Welcome to TSDN.

      What you want, if I am not wrong..... You want a String as a Vector Element.
      Or, (String)new Vector().

      Kind regards,
      Dmjpro.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by dmjproOr, [B
        (String)new Vector()[/B].

        Kind regards,
        Dmjpro.
        That cast will fail miserably; even the compiler can detect that. Maybe you mean:

        [code=java]
        (new Vector()).toStr ing();
        [/code]

        ... which doesn't do anything useful either.

        kind regards,

        Jos

        Comment

        • Nepomuk
          Recognized Expert Specialist
          • Aug 2007
          • 3111

          #5
          Originally posted by JosAH
          That cast will fail miserably; even the compiler can detect that. Maybe you mean:

          [code=java]
          (new Vector()).toStr ing();
          [/code]

          ... which doesn't do anything useful either.

          kind regards,

          Jos
          Or maybe you mean:
          [CODE=java]String someString = (String) Vector.elementA t(i);[/CODE]
          However, if you're using Java 1.5 or later, just use the Vector like this:
          [CODE=java]
          Vector<String> someVector = new Vector<String>( );
          someVector.add( "Hi there!");
          String someString = someVector.elem entAt(0);
          [/CODE]

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            I changed the thread title but I still have no idea if it reflects what the OP needs.

            kind regards,

            Jos

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by JosAH
              I changed the thread title but I still have no idea if it reflects what the OP needs.

              kind regards,

              Jos
              Stumped me as well that's why I'd left it like that.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by r035198x
                Stumped me as well that's why I'd left it like that.
                I'm afraid this is one of the many threads that become forgotten threads. It happens
                all the time; quite disappointing if you'd ask me: an OP asks a vague question;
                people try to help and ask further questions and then: void, silence, the abyss;
                I wonder if the OPs are happy with it ...

                kind regards,

                Jos

                Comment

                • aquatone282
                  New Member
                  • Sep 2007
                  • 1

                  #9
                  Originally posted by JosAH
                  I'm afraid this is one of the many threads that become forgotten threads. It happens
                  all the time; quite disappointing if you'd ask me: an OP asks a vague question;
                  people try to help and ask further questions and then: void, silence, the abyss;
                  I wonder if the OPs are happy with it ...

                  kind regards,

                  Jos
                  However, someone randomly surfing through the forums (myself), may find the responses very helpful.

                  Thanks!

                  Comment

                  • Nepomuk
                    Recognized Expert Specialist
                    • Aug 2007
                    • 3111

                    #10
                    Originally posted by aquatone282
                    However, someone randomly surfing through the forums (myself), may find the responses very helpful.

                    Thanks!
                    Well, that's at least one person we've helped! ^^

                    Comment

                    • ttamilvanan81
                      New Member
                      • Mar 2007
                      • 35

                      #11
                      Originally posted by ravinttf32
                      how to pass string as vector object

                      If u want to pass the String value as Vector object, like this

                      Code:
                      String name = "ravinttf32";
                      java.util.Vector vector = new java.util.Vector();
                      vector.addElement(name);
                      request.setAttribute("sendreqvector",vector);
                      otherwise, if u want to pass the vector Element as String object, like this

                      Code:
                      java.util.Vector vector = (java.util.Vector)request.getAttribute("sendreqvector");
                      String name="";
                      for(int i=0;i<vector.size(); i++)
                      {
                           name = String.valueOf(vector.elementAt(0));
                      }
                      request.setAttribute("sendreqname",name);
                      Is it clear...

                      Comment

                      Working...