简体   繁体   English

如何为一个Object []分配多个值?

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

I am using this piece of code to insert into hashmap. 我正在使用这段代码插入到hashmap中。

I have assigned the multiple values to the Object[] , but when I run the program I am getting these errors. 我已将多个值分配给Object[] ,但是运行程序时出现这些错误。

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. 在周围添加另一组{ } ,并使用[][]表示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"}  };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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