简体   繁体   中英

How can I assign multiple values to an Object[]?

I am using this piece of code to insert into hashmap.

I have assigned the multiple values to the Object[] , but when I run the program I am getting these errors.

How can I solve this error:

<identifier> expected
illegal start of type
 ';' expected

Code:

public final static Object[] longValues = {"10", "iosl-proi", "10.10.10.10.10.","5","O"},{"11", "pree-lee1", "12.1.2.","4","O"},{"13", "trtg-lv1t", "4.6.1.","3","O"};

You appear to be creating a multi-dimensional array. Perhaps this is what you want?

public final static Object[][] longValues = {
    {"10", "iosl-proi", "10.10.10.10.10.","5","O"},
    {"11", "pree-lee1", "12.1.2.","4","O"},
    {"13", "trtg-lv1t", "4.6.1.","3","O"}
};

Although, given the pattern in your object values, perhaps you actually want to create a class to store these values?

Add another set of { } around and use [][] to denote an Array of Array.

public final static Object[][] longValues =
             {{"10", "iosl-proi", "10.10.10.10.10.","5","O"},
              {"11", "pree-lee1", "12.1.2.","4","O"},
              {"13", "trtg-lv1t", "4.6.1.","3","O"}};

In your code you are assigning multidimensional array to single dimensional array.You need to create multidimensional array as below.

public final static Object[][] longValues =
            { {"10", "iosl-proi", "10.10.10.10.10.","5","O"},
              {"11", "pree-lee1", "12.1.2.","4","O"},
              {"13", "trtg-lv1t", "4.6.1.","3","O"}  };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM