ham ham - 4 months ago 11
Java Question

what is the most efficient way to sweep a list

i have a large list of tuples

List<Tuple2<String,String> list;


what is the most efficient way to sweep it to search an element to retreive it or modify it??

for eg:

String elementToSearch="l";
list={(a,hh)(b,rr)(c,kk)(d,jj)(l,mm).....}
Tuple2<String,String> result=(l,mm)


i tried that using the loop "for", it worked, but because it s a large list, i am not sure if it is the best way to do it.

Answer

You probably need a Map...

Map<String, String> myMap = new HashMap<>();

myMap.put("a", "bb");
//...

String result = myMap.get("a");
//result will be "bb"