Implement a vector that accepts anything

2

I have to implement a vector that is capable of storing objects of any type. For example: V[3]= valor_int,valor_double,valor_float,valor_String . To do this I was thinking of creating a method that would parse the values I want to insert, would it be the best way out?

    
asked by anonymous 26.05.2016 / 20:03

1 answer

3

The solution is simpler than the one in the question, it is only by comments that you realize that it is just an array of objects. So just declare that the type is Objeto :

Object[] array = new Object[5];

See working on ideone and on CodingGround .

But note that the data will be stored in a boxed form. You will not use a int , but a Integer , although the value is the same, the form is quite different and has important consequences. At the moment Java is the same and can not do more optimally.

    
26.05.2016 / 21:26