You can't. When you create an array, you have to declare its type, and then the array can only store elements of that type.
However, you can use more sophisticated containers than arrays for storing things. Here is an example using a container called an ArrayList to store doubles and Strings:
Using collection classes, like an ArrayList, is a little bit tricky. When you try to add an object like a String to an ArrayList, Java automatically converts the String to type Object before adding it. So really, just like with an array, you are limited to storing only one type, i.e. type Object. But, the Object class is the base class for all classes, including user created classes. Therefore, any object can be converted to type Object, and therefore only being able to store Object types in an ArrayList is really not a limitation--it's only a hindrance. The hindrance being that when you retrieve the elements of your ArrayList, you get them returned to you as type Object, so you have to convert them back to their orignal type.
If you add only objects of the same type to an ArrayList, for instance all String objects, then you can just cast every element to a String immediately after retrieving it, e.g.
On the other hand, if you add objects of various types to an ArrayList, for instance objects of type Double and objects of type String, then after you retrieve an element from the ArrayList, you don't necessarily know to what type you should cast the element. In that case, you can use the instanceof operator to determine what type is actually stored in the returned Object element in order to cast it to the right type. [ October 06, 2006: Message edited by: sven studde ]
Originally posted by sven studde: You can't. When you create an array, you have to declare its type, and then the array can only store elements of that type.
You can't store floats and Strings in the same array, but you can store Floats and Strings in an array of Objects. (The capital F in Float means we are talking about the wrapper class java.lang.Float).
It would not usually be good design to do this, however. Perhaps you should take a step back and see if another data structure than 2D arrays would be more suitable. Perhaps tell us what you're really trying to achieve.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.