I've got List<Long> dynamics. And I want to get max result using Collections. This is my code:
List<Long> dynamics=spyPathService.getDynamics();
Long max=((Long)Collections.max(dynamics)).longValue();
This is my getDynamics:
public List<Long> getDynamics() {
Session session = null;
session = this.sessionFactory.getCurrentSession();
Query query = session
.createSQLQuery("SELECT COUNT(*) FROM SpyPath WHERE DATE(time)>=DATE_SUB(CURDATE(),INTERVAL 6 DAY) GROUP BY DATE(time) ORDER BY time;");
List<Long> result = query.list();
return result;
}
Now I'm getting java.math.BigInteger cannot be cast to java.lang.Long. What's wrong?
BigIntegerto aLong.java.math.BigIntegerclass instance is not an instance ofjava.lang.Longclass.Collections.max(dynamics))isBigInteger, and you are trying cast it to long, try to cast it toBigInteger, and then uselongValue()methodList<Long>. @Tony Check the return type ofspyPathService.getDynamics(). Assuming your error is actually coming from these lines of code, I would guess from this code that spyPathService.getDynamics() is actually returning a List that at the very least includes someBigIntegers