Results 1 to 5 of 5
  1. #1
    ulykidjoe is offline Member
    Join Date
    Jul 2007
    Posts
    3
    Rep Power
    0

    Default Unify these 3 lines of code

    Hi people,
    I have these codes:
    Java Code:
    java.util.Vector columns = new java.util.Vector();
    columns.addElement("..#directory");
    rows.insertElementAt(columns, 0);
    I Would like to write them in just one line of code like
    Java Code:
    rows.insertElementAt(new java.util.Vector() ..., 0)
    by i dont know the correct syntax.
    Can you help me.
    Thanks a lot.

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    Try this:

    Java Code:
    rows.insertElementAt((new Vector()).addElement("..#directory"), 0);

  3. #3
    ulykidjoe is offline Member
    Join Date
    Jul 2007
    Posts
    3
    Rep Power
    0

    Default

    Thanks for Your reply but im getting an error: "'void' type not allowed here." with your code, what might be wrong??

  4. #4
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    Hmm, that is right addElement method returns void and you can not add void to rows vector.

    You can't do that in one line because Vector constructor does not accept the first element of the vector as a parameter. You should use at least three lines like you have given.

  5. #5
    ulykidjoe is offline Member
    Join Date
    Jul 2007
    Posts
    3
    Rep Power
    0

    Default

    Okay thank you very much for your time, now at least i can rest in peace :)

Similar Threads

  1. how can we remove blank lines from a .txt
    By Camden in forum New To Java
    Replies: 12
    Last Post: 07-29-2011, 01:38 PM
  2. Replies: 0
    Last Post: 04-06-2008, 07:45 PM
  3. Removing empty lines from code using Eclipse
    By javaplus in forum Eclipse
    Replies: 1
    Last Post: 12-14-2007, 09:21 PM
  4. Joining lines in Eclipse
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-04-2007, 11:17 AM
  5. how to edit lines.
    By jason27131 in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 04:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •