Unify these 3 lines of code

Hi people,

I have these: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, something like:rows.insertElementAt(new java.util.Vector() ...,0)

by i dont know the correct syntax.

Can you help me.

Thanks a lot.

[469 byte] By [kidjoea] at [2007-11-27 10:29:11]
# 1

It can be done, but it's ugly and unintuitive. Why specifically do you want to do it on one line? It won't be "efficient" or anything - the opposite, probably - since bytecode doesn't really have a concept of "lines". If you really want to, here it is, but I'd advise against it

rows.insertElementAt(new Vector() { {addElement("..#directory");} }, 0);

What I've done is created an anonymous subclass of Vector, which has an initializer that adds the element you want. Hideously ugly and nasty, please don't do it!

georgemca at 2007-7-28 17:56:02 > top of Java-index,Java Essentials,Java Programming...