Search

Programs for Interview

Java 8, Stream API, Lambda, Functional Interface, HashMap, HashSet Java 8, Stream API, Lambda, Functional Interface, HashMap, HashSet

🧠 1. Find Even Numbers using Stream

List<Integer> list = Arrays.asList(1,2,3,4,5,6);
list.stream().filter(n -> n % 2 == 0).forEach(System.out::println);

🧠 2. Convert List to Uppercase

List<String> names = Arrays.asList("java","python");
names.stream().map(String::toUpperCase).forEach(System.out::println);

🧠 3. Find Duplicate Elements

List<Integer> list = Arrays.asList(1,2,3,2,4,1);
Set<Integer> set = new HashSet<>();
list.stream().filter(n -> !set.add(n)).forEach(System.out::println);

🧠 4. Count Frequency using HashMap

String str = "java";
Map<Character,Integer> map = new HashMap<>();
for(char c : str.toCharArray()){
map.put(c, map.getOrDefault(c,0)+1);
}
System.out.println(map);

🧠 5. Sort List using Lambda

List<Integer> list = Arrays.asList(5,2,8,1);
list.sort((a,b) -> a - b);
System.out.println(list);

🧠 6. Find Max Number using Stream

List<Integer> list = Arrays.asList(1,5,3,9);
int max = list.stream().max(Integer::compare).get();
System.out.println(max);

🧠 7. Find First Non-Repeating Character

String str = "aabbcde";
Map<Character,Long> map = str.chars()
.mapToObj(c -> (char)c)
.collect(Collectors.groupingBy(c -> c, LinkedHashMap::new, Collectors.counting()));

map.entrySet().stream()
.filter(e -> e.getValue() == 1)
.findFirst()
.ifPresent(System.out::println);

🧠 8. Reverse String using Stream

String str = "hello";
String rev = new StringBuilder(str).reverse().toString();
System.out.println(rev);

🧠 9. Remove Duplicates from List

List<Integer> list = Arrays.asList(1,2,2,3);
list.stream().distinct().forEach(System.out::println);

🧠 10. Sum of Numbers using Stream

int sum = Arrays.asList(1,2,3,4).stream().mapToInt(i -> i).sum();
System.out.println(sum);

🧠 11. Group Strings by Length

List<String> list = Arrays.asList("hi","hello","hey");
Map<Integer,List<String>> map = list.stream()
.collect(Collectors.groupingBy(String::length));
System.out.println(map);

🧠 12. Check Palindrome using Lambda

String str = "madam";
boolean isPal = str.equals(new StringBuilder(str).reverse().toString());
System.out.println(isPal);

🧠 13. Functional Interface Example

@FunctionalInterface
interface Test {
void show();
}

Test t = () -> System.out.println("Hello");
t.show();

🧠 14. Sort Map by Value

Map<String,Integer> map = new HashMap<>();
map.put("A",3); map.put("B",1);

map.entrySet().stream()
.sorted(Map.Entry.comparingByValue())
.forEach(System.out::println);

🧠 15. Count Words in Sentence

String str = "java is java";
Map<String,Long> map = Arrays.stream(str.split(" "))
.collect(Collectors.groupingBy(w -> w, Collectors.counting()));
System.out.println(map);

🧠 16. Find Second Highest Number

List<Integer> list = Arrays.asList(1,5,8,3);
int second = list.stream().sorted(Collections.reverseOrder()).skip(1).findFirst().get();
System.out.println(second);

🧠 17. Merge Two Lists

List<Integer> l1 = Arrays.asList(1,2);
List<Integer> l2 = Arrays.asList(3,4);
List<Integer> merged = Stream.concat(l1.stream(), l2.stream()).collect(Collectors.toList());
System.out.println(merged);

🧠 18. Convert List to Map

List<String> list = Arrays.asList("A","B");
Map<String,Integer> map = list.stream()
.collect(Collectors.toMap(s -> s, String::length));
System.out.println(map);

🧠 19. Find Longest String

List<String> list = Arrays.asList("java","spring","boot");
String longest = list.stream().max(Comparator.comparing(String::length)).get();
System.out.println(longest);

🧠 20. Filter Null Values

List<String> list = Arrays.asList("a",null,"b");
list.stream().filter(Objects::nonNull).forEach(System.out::println);

🧠 21. HashSet Example (Unique Elements)

Set<Integer> set = new HashSet<>(Arrays.asList(1,2,2,3));
System.out.println(set);

🧠 22. Find Intersection of Two Lists

List<Integer> l1 = Arrays.asList(1,2,3);
List<Integer> l2 = Arrays.asList(2,3,4);
l1.stream().filter(l2::contains).forEach(System.out::println);

🧠 23. Count Characters using Stream

String str = "hello";
Map<Character,Long> map = str.chars()
.mapToObj(c -> (char)c)
.collect(Collectors.groupingBy(c -> c, Collectors.counting()));
System.out.println(map);

🧠 24. Sort Strings Alphabetically

List<String> list = Arrays.asList("banana","apple");
list.stream().sorted().forEach(System.out::println);

🧠 25. Find Any Element using Stream

List<Integer> list = Arrays.asList(1,2,3);
list.stream().findAny().ifPresent(System.out::println);

Become a member

Get the latest news right in your inbox. We never spam!

Welcome to Skill to Growth - technology-focused learning blog, created for developers who want to build strong, real-world skills and grow confidently in their careers. I started this blog with one clear mission: to make learning technology simple, practical, and career-oriented for anyone who truly wants to grow. In a world full of scattered tutorials and half-explained concepts, this platform is built to give you clarity, structure, and confidence. This blog covers Android development, Flutter, React Native, Spring Boot, DevOps, and Git, designed carefully from absolute beginner to industry-ready level. Every topic here is written with the mindset of real-world application, not just theory. I believe that learning should not feel confusing or intimidating. That’s why each article focuses on strong fundamentals, clean explanations, and step-by-step learning paths that actually make sense. If you are a student starting from zero, this blog helps you build a solid foundation. If you are a working professional, it helps you upgrade your skills, stay relevant, and move ahead in your career. You’ll learn how to build mobile applications, create powerful backend systems, manage code using Git, and deploy applications using modern DevOps practices. More importantly, you’ll understand how everything connects, so you think like a complete developer—not just a coder. This platform is for those who are serious about their growth, who want more than just copy-paste tutorials. It’s for learners who want confidence in interviews, clarity in projects, and stability in their careers. Technology changes fast, but strong fundamentals and the right mindset never go out of date. This blog exists to help you build both. If you’re ready to invest in yourself, stay consistent, and learn the right way— you’re in the right place.
Comments
Leave a Comment

Login OR Register to write comments