Open DevShivmohan opened 3 months ago
@rahulmech12 @anuragrawat7
Here is the list inside the parent list has multiple list and inside the sublist has multiple values so we have to print the anyone element from any sub list
List<List<String>> listStrings = new ArrayList<>();
listStrings.add(List.of("Sh","Moh","Rahul"));
listStrings.add(List.of("Anu","Anuraga","Rahula"));
String value = listStrings.stream().findFirst().get().stream().findFirst().get();
System.out.println(value);
Here is the list has multiple values so we have to find get any single value
List<String> list = List.of("Sh","Moh","Rahul");
String valueWithDefault = list.stream().findFirst().orElse("default value"); // if not any values in the list then it return default
String value = list.stream().findFirst().get();
System.out.println(valueWithDefault);
System.out.println(value);