[英]Multi-Dimensional Array(or other structure) in Java
I come from PHP, i'm developping a tool, and i need to use a multidimensional array ( or something other, map,..) My goal is to be able to have an ArrayList like that :我来自 PHP,我正在开发一个工具,我需要使用多维数组(或其他东西,map,..)我的目标是能够拥有这样的 ArrayList:
[["name1", "surname1", "age"], ["name1", "surname1", "age"]]
Or :
[["name" : "name1", "surname" : "surname1", "age" : "age1"], ["name" : "name2", "surname" : "surname2", "age" : "age2"]]
And to be able to add another list into this global list, without size limit.并且能够将另一个列表添加到这个全局列表中,没有大小限制。 Actually, i do not found that in Java, it's crazy xD.
实际上,我没有发现在 Java 中,这是疯狂的 xD。
The goal after that it to filter (with something like in PHP ((multi sort) to be able to sort those arrays which areinside the global array.之后的目标是过滤(使用类似于 PHP 中的((多排序))能够对全局数组内的那些数组进行排序。
( I need to sort a key of those list,in order to get the most recent, and then i save the first list which is the most recent ). (我需要对这些列表的键进行排序,以获得最新的,然后我保存最新的第一个列表)。
So actually, i only arrive to get an arraylist.. but not multidimensionnal..所以实际上,我只是为了得到一个数组列表..但不是多维..
Thanks for tips :) (I use spring boot )感谢您的提示:)(我使用弹簧靴)
EDIT 1 :编辑 1:
HashMap<String, String> myhash = new HashMap<String, String>();
myhash.put("Cat1", "james");
myhash.put("Cat2", "adams");
myhash.put("Cat3", "turk");
System.out.println(myhash);
// {Cat3=turk, Cat2=adams, Cat1=james}
// I Would like : [{Cat3=turk, Cat2=adams, Cat1=james}, {Cat3=turkother, Cat2=adamsother, Cat1=jamesother}, {Cat3=fred, Cat2=ded, Cat1=tp}]
You mean HashMap<String, ArrayList<String>>
and than use filter on the HashMap.keyset()
.你的意思是
HashMap<String, ArrayList<String>>
而不是在HashMap.keyset()
上使用过滤器。
But don't know if this is exactly what your are looking for.但不知道这是否正是您要寻找的。
Two notes:两个注意事项:
Person
with the required properties, store it in an ArraysList
and than use this object further.Person
,将其存储在ArraysList
然后进一步使用该对象。 Update:更新:
HashMap<String, String> myhash = new HashMap<String, String>();
myhash.put("Cat1", "james");
myhash.put("Cat2", "adams");
myhash.put("Cat3", "turk");
System.out.println(myhash);
// {Cat3=turk, Cat2=adams, Cat1=james}
// I Would like : [{Cat3=turk, Cat2=adams, Cat1=james}, {Cat3=turk, Cat2=adams, Cat1=james}]
ArrayList<HashMap<String, String>> lst = new ArrayList<>();
lst.add(myhash);
lst.add(myhash);
System.out.println(lst); //[{Cat3=turk, Cat2=adams, Cat1=james}, {Cat3=turk, Cat2=adams, Cat1=james}]
Remark:评论:
myhash
is added twice ==> if you change on the one field ==> changes on the other field is done as wellmyhash
被添加两次 ==> 如果你改变了一个字段 ==> 另一个字段的更改也完成了以下是在 Java 中获得列表列表的方式。
ArrayList<ArrayList<String>> myList = new ArrayList<>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.