Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is this construction for : Object[]{value1,value2}?

Tags:

java

object

can someone explain to me what

new Object[]{test_name,test_laenge};

means? will it just create a new one dimensional Object with 2 tuple values test_name and test_laenge?

I used this in this construction to extract values from a Database into a resultset and insert those value-tuples into a 2-column JTable...

((DefaultTableModel)table.getModel()).addRow(new Object[]{test_name,test_laenge});

but I dont really understand how this works...

like image 360
Marc_L Avatar asked May 03 '26 02:05

Marc_L


2 Answers

It creates an array of size two, where the entries in the array are test_name and test_laenge

It is the same as:

Object[] array = new Object[2];
array[0] = test_name;
array[1] = test_laenge;
((DefaultTableModel)table.getModel()).addRow(array);

The entries in the array is treated as columns and adds one row in the database.

like image 196
Simon Forsberg Avatar answered May 05 '26 15:05

Simon Forsberg


new Object[]{test_name,test_laenge};

creates a new array (Object[]) with two elements: test_name and test_laenge.

The actual elements are the objects referenced by the two variables.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!