commit
7eb338f990
|
@ -15,21 +15,24 @@ import org.junit.Test;
|
||||||
public class MapFirstPairUnitTest {
|
public class MapFirstPairUnitTest {
|
||||||
|
|
||||||
private Map.Entry<Integer, String> getFirstPairUsingIterator(Map<Integer, String> map) {
|
private Map.Entry<Integer, String> getFirstPairUsingIterator(Map<Integer, String> map) {
|
||||||
if (map == null || map.size() == 0)
|
if (map == null || map.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Iterator<Map.Entry<Integer, String>> iterator = map.entrySet()
|
Iterator<Map.Entry<Integer, String>> iterator = map.entrySet()
|
||||||
.iterator();
|
.iterator();
|
||||||
|
|
||||||
if (iterator.hasNext())
|
if (iterator.hasNext()) {
|
||||||
return iterator.next();
|
return iterator.next();
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map.Entry<Integer, String> getFirstPairUsingStream(Map<Integer, String> map) {
|
private Map.Entry<Integer, String> getFirstPairUsingStream(Map<Integer, String> map) {
|
||||||
if (map == null || map.size() == 0)
|
if (map == null || map.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Set<Map.Entry<Integer, String>> entrySet = map.entrySet();
|
Set<Map.Entry<Integer, String>> entrySet = map.entrySet();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue