[56, SensIOP, 9, Open Point] - Index 0
[562, SensIOP, 92, Open Point2] - Index 1
这是我从数据库调用中获取的对象。我在列表上进行迭代以获取此信息,现在我的问题是第1和第3个字段很长而其他字段是字符串,如何从对象中提取它,将它分配给某个变量。
更新:
Object object = (Object) iterator.next();
此对象的值设置为1(索引0)(它在for循环中)
更新2:
for (Iterator iterator = List2.iterator(); iterator.hasNext();) {
Object object = (Object) iterator.next();
答案 0 :(得分:1)
答案 1 :(得分:1)
using this function you can get result :
String a1= arrayname[0] ; //[56, SensIOP, 9, Open Point]
a1=split(',',a1);
String Fisrtval=a1[0];
String Thirdtval=a1[2];
请参阅:http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/util/StringHelper.html#split(java.lang.String,java.lang.String)
答案 2 :(得分:1)
我不知道您是如何获取数据的,但是当我以您指定的格式获取数据时,我会执行以下操作:
List<Object[]> objects = query.list();
if (objects.size() > 0) {
for (int j = 0; j < objects.size(); j++) {
Object[] object = objects.get(j);
BigInteger firstValue = (BigInteger) object[0];
String secondValue = (String) object[1];
BigInteger thirdValue = (BigInteger) object[2];
String forthValue = (String) object[3];
long firstValueLong = firstValue.longValue();
long thirdValueLong = thirdValue.longValue();
}
}
答案 3 :(得分:0)
我在'RAS'的帮助下找到了结果,发表了作品greate thanks
List<Object> resultList =(List<Object>) em.createNativeQuery("SELECT isbillpayable,isothracctrfable FROM usrfacaccounts ").getResultList();
for (Iterator<Object> it = resultList.iterator(); it.hasNext();) {
Object[] object = (Object[]) it.next();
String firstValue = (String) object[0];
System.out.println("isbillpayable"+firstValue);
}