Reputation: 475
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"};
Upvotes: 0
Views: 231
Reputation: 51721
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"}};
Upvotes: 1
Reputation: 3078
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"} };
Upvotes: 1
Reputation: 69410
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?
Upvotes: 6