For development of web services, i have to make multilevel Associative array as follows
Array
(
[0] => Array
(
[id] => 1100
[content] => This is content
[creator_info] => Array
(
[id] => 1
[fname] => abc
[lname] => xyz
)
[tag_info] => Array
(
[0] => Array
(
[id] => 3
[name] => my
)
[1] => Array
(
[id] => 4
[name] => you
)
[2] => Array
(
[id] => 5
[name] => your
)
)
[created_date] => 14 JAN 2012
)
[1] => Array
(
[id] => 1101
[content] => This is content1
[creator_info] => Array
(
[id] => 2
[fname] => abc1
[lname] => xyz1
)
[tag_info] => Array
(
[0] => Array
(
[id] => 35
[name] => wer
)
[1] => Array
(
[id] => 47
[name] => cvb
)
[2] => Array
(
[id] => 51
[name] => mnv
)
)
[created_date] => 15 JAN 2012
)
)
with referencing this question, i am using ArrayList
.
as follows
Java doesn't have associative arrays like PHP does.
There are various solutions for what you are doing, but it depends on how you want to look up the information. You can easily write a class that holds all your information and store instances of them into an ArrayList.
public class Foo{
public String name, fname;
public Foo(String name,String fname){
this.name=name;
this.fname=fname;
}
}
And then...
List<Foo> foos = new ArrayList<Foo>();
foos.add(new Foo("demo","fdemo");
foos.add(new Foo("test","fname");
So you can access them like...
foos.get(0).name;
=> "demo"
This keeps me happy for single level. If i keeps continue with it, this looks like as a complicated procedure.
I wants something simple procedure with high speed.
Last 3 days i am working in it and i got the success for following
Map<String,Object> myMap1 = new HashMap<String, Object>();
List<Map<String , Object>> myMap = new ArrayList<Map<String,Object>>();
Map<String,String> user_info = new HashMap<String, String>();
user_info.put("fname", "xyz");
user_info.put("lname", "pqr");
myMap1.put("id", 20);
myMap1.put("content", "This is content");
myMap1.put("creator_info", user_info);
myMap1.put("timestamp", "11 Jan 2012");
myMap.add(0,myMap1);
still not getting that how to do it for tags_info
is there any library for this thing....?