How to store different types of data in an array (java)

1

Good evening I have a problem I have created a table, which I want to add an event that when I click save me data of different types either double , Object e integer .

            int numCols = table.getModel().getColumnCount();
            Object [] fila = new Object [numCols]; 

             fila[0] = txtcodigo.getText();
             fila[1] = txtnombre.getText();
             fila[2] = txtmarca.getText();
             fila [4] = txtprecio.getText(); // aquí es donde quiero guardar 
                                             // datos tipo double
    
asked by Husiel Ruiz 19.11.2018 в 03:57
source

1 answer

0

Since you have an arrangement of objects, you can perfectly store Double 's in this:

Taking your code as an example, let's use the static method valueOf of the class Double , which accepts a string as a parameter, interprets it and returns an instance of the class with the number it represents, it would be something as:

fila[4] = Double.valueOf(txtprecio.getText()); 
    
answered by 19.11.2018 / 05:21
source