CollectionsUtil { public static <T> Optional<T> findAnyIn(Collection<T> collection) { final Iterator<T> iterator = collection.iterator(); if (iterator.hasNext()) { return Optional.of(iterator.next()); } return Optional.empty(); } private  CollectionsUtil(); static Optional<T> findAnyIn(Collection<T> collection); static T getAnyFrom(Collection<T> collection);  }
@Test void findAnyIn() { final List<String> populatedList = Collections.singletonList("value"); final Optional<String> populatedOptional = CollectionsUtil.findAnyIn(populatedList); assertTrue(populatedOptional.isPresent()); assertEquals("value", populatedOptional.get()); final List<String> emptyList = Collections.emptyList(); final Optional<String> emptyOptional = CollectionsUtil.findAnyIn(emptyList); assertFalse(emptyOptional.isPresent()); }