简体   繁体   中英

Get single element from a List Java

在此处输入图片说明

I have above result list. I need to get one element or value from that list. How to achieve this.

public List<OriginTransactionsVM> findTransactionsOfOrigin(String origin_id) {

    List result=null;
    try {

        Query query = getSession().createSQLQuery("CALL getOriginTransactions(:string_acc_no)")
                .setParameter("string_acc_no", origin_id);
         result= query.list();

        // String rep =  (String) result.get(0);   need to achieve this result.get(0)[0] something like this

    } catch (Exception ex) {
        throw ex;
    }
    return result;
}

This should help you:

Object[] resultArray = (Object[]) result.get(0);
String rep = (String) resultArray[0];

您可以使用以下方法获取索引处的元素,

list.get(index);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM