gpt4 book ai didi

java - 如何从 List 中检索每个值
转载 作者:行者123 更新时间:2023-11-30 08:51:54 24 4
gpt4 key购买 nike

当我执行这个查询时,我将结果存储到列表对象中

Query vodquery = session.createQuery(
"select vod.videoid,vod.videotitle,alb.language,alb.genre "+
"from Videos as vod,Album as alb "+
"where vod.videoType =:videotype and vod.albumId=alb.id "+
"group by vod.videoId").setParameter("videotype","MOV");
List<Object> videolist = vodquery.list();

我需要检索每个结果,但是当我使用这段代码时

for(int i = 0; i < videolist.size(); i++) {
System.out.println(videolist.get(i));
}

结果是

[Ljava.lang.Object;@b7e548
[Ljava.lang.Object;@12e0986
[Ljava.lang.Object;@1735396

当我使用这段代码时

for (int i=0; i<videolist.size(); i++){
Object[] row = (Object[]) videolist.get(i);
System.out.println("Element "+i+Arrays.toString(row));
}

结果是这样的

Element 0[VOD1000, sdf, English, Action, null, d, Entertainment, Action, comody, 0, null, null, dddddd]

Element 1[VOD1002, sdf, NONE, NONE]
Element 2[VOD1004, sdf, NONE, NONE]
Element 3[VOD1005, sdf, NONE, NONE]

但我需要从每一行中获取每个值。我怎样才能做到这一点。我需要遍历结果中的每个值

最佳答案

改变你的循环:

for (int i=0; i < videolist.size(); i++){
Object[] row = (Object[]) videolist.get(i);
for(Object obj : row) {
System.out.println("Element "+ i +obj));
}
}

关于java - 如何从 List<Object> 中检索每个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30366292/

24 4 0