gpt4 book ai didi

java - 打印包含字符串和对象列表的 HashMap

转载 作者:行者123 更新时间:2023-11-30 07:00:48 24 4
gpt4 key购买 nike

如何打印包含字符串和对象列表的 HashMap?

HashMap<String, List<Object>> Map = new HashMap<String, List<Object>>();

每个对象都有一个名称和一个键值,所以我需要得到如下内容:

StringFirst = [ firstObject 15, second object 31, thirdobject 16]
StringSecond = [ fourthObject 15, fifthObject 31, sixthObject 16]

public static class Graph {

public class Edge extends Graph {
String edgeName;
int time;

Edge(String edgeName, int time){
this.edgeName = edgeName;
this.time = time;
}

public void Out(){
System.out.println(this.edgeName);
System.out.println(this.time);
}
}

最佳答案

尝试打印 map :

for(Map.Entry<String, ArrayList<Edge>> e : map.entrySet()){
for(Edge e1 : e.getValue())
System.out.println(e.getKey() + " = "+ e1.Out());
}

关于java - 打印包含字符串和对象列表的 HashMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30244558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com