Reputation: 1
Hello and sorry for the noobish question. I have done a lot of search about my problem but i found nothing related to my problem.
So i have something like this:
public static String something [][] =
{
{"1","100"},
{"2","1000"},
{"3","10000"}
};
public static String somethingelse [][] =
{
{"1","100"},
{"2","1000"},
{"3","10000"}
};
public static String CATEGORIES[][][] =
{
something,
somethingelse
};
How and if it is possible ofcourse can i return from the CATEGORIES[something].get(1st line) line?
I dont want to use something[0] I want to use something like this CATEGORIES.something[0] i dont know how else to explain it.
Thanks in advance!
Upvotes: 0
Views: 50
Reputation: 4039
You could use a HashMap with the key-value pairs as the name of the list and an arraylist like this:
HashMap<String, ArrayList<String>> c = new HashMap<>();
ArrayList<String> s = new ArrayList<>();
s.put("HI");
s.put("HELLO");
ArrayList<String> s2 = nee ArrayList<>();
s2.put("HI Again!");
s2.put("Hello Again");
c.put("something", s);
c.put("something2", s2);
Then you can access them as
c.get("something").get(0);
Note: Sorry for the inconvenient variable names, I'm on a phone.
Upvotes: 1
Reputation: 5048
You can (but it is an awful practice) with this:
public static class Categories {
public String something [][] = {
{"1","100"},
{"2","1000"},
{"3","10000"}
};
public String somethingelse [][] = {
{"1","100"},
{"2","1000"},
{"3","10000"}
};
}
public static final Categories CATEGORIES = new Categories();
Upvotes: 1