java - Storing multiply objects, or instances in one array index -


Is it possible for Java to store multiple objects in an array index? For example object 1 and object 2, which are string variables that can be referenced by array [1]

  string [] text = new string [] text [1] = "rabbit "Now if I output text [1] it will produce both wire" rabbit "and" horse "then [text] [1] =" horse " 

And is it possible to refer to several array indexes for one object? For example, the object1 = array [1] and array [2] says.

I have more interest in the first example. And if possible please give me an example of action for this.

The way you showed it is impossible in your example text [1] for your string object The context is, so you are overriding a reference (rabbit) with reference to a string (horse).

Store two strings in objects [0]:

  object [] objects = new object [] {new string [] {"one", "b"} , Blank, empty;};  

Storing two references in a single array consistently as two fields (an object is referred to multiple array indexes):

  object O = new string ("a"); Objects [1] = o; Objects [2] = o;  

Another solution for you:

  object [] text = new object [] (new array list & lt; string & gt; (), Blank, zero}; text [0] .add ("rabbit"); text [0] .add ("horse");  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -