java - Finding Member of First ArrayList with Highest Value in Second ArrayList -



java - Finding Member of First ArrayList with Highest Value in Second ArrayList -

i have arraylist of objects 2 parameters (name, value). have arraylist of different type of objects 2 other parameters (value, suit). each user corresponds (by index of 0-3) object in sec list same index.

i need find user who's value highest in sec list.

how can concisely? sense i'm missing simple here.

assuming name-value tuple type namevalue, , assuming other tuple type valuesuit might like,

list<namevalue> firstlist; list<valuesuit> secondlist; // ... firstlist , secondlist initialized ...

first, maximum value in sec list.

int maxvalue = secondlist.get(0).getvalue(); (valuesuit vs : secondlist) { maxvalue = math.max(maxvalue, vs.getvalue()); }

then find corresponding namevalue

namevalue out = null; (namevalue nv : firstlist) { if (nv.getvalue() == maxvalue) { out = nv; } } system.out.println(out);

java arraylist compare

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -