+ 1
How to display the values of a 2D mixed array String and Int?
I need to display values of a 2D array. There each Int value have their own String. Object[] [] sword = New Object[2] [2] sword[0] [0] = "Short sword" ; sword[0] [1] = "Name" ; //type - Name, Name of sword - Short Sword sword[1] [0] = 100 ; sword[1] [1] = "Prise" ; // type - Prise, the Prise of sword - 100 It must be: Name : Short sword Prise : 100
2 Réponses
+ 2
Instead of using a 2D array, you should use something more like a dictionary which uses key value pairs to store a variety of information.
Info = {Name: "Short sword", Price: 100};
+ 2
You can test your data to tell which class it is (using instanceof.) Then, type cast it.
https://www.webucator.com/how-to/how-check-object-type-java.cfm