Filter list of objects without using hashmap java

balajiprasadb

Let's say I have a list of objects - Student(s). Each student object has various properties - roll number, class name (Not to be confused with Java class name, this is student's class name), student name etc.

The requirement is to retrieve student objects which have class name say "stack overflow". We may create a hashmap with classname (String) and it's respective student object. Is there any other solution in java which does not use hashmap? I have come across various requirements like these where generally I create an hashmap and move ahead. I'm just curious if there is a better way to solve problems like these.

Birbal Singh

Using java 8 stream api

Student result1 = list.stream()                        // Convert to steam
                .filter(x -> "rahul".equals(x.getName()))        // we want "rahul" only
                .findAny()                                      // If 'findAny' then return found
                .orElse(null); 

And to collect list

List<Student> result1 = list.stream()                        // Convert to steam
          .filter(x -> "rahul".startsWith(x.getName()))
          .collect(Collectors.toList());

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Java Stream: List of objects to HashMap without duplicates

From Dev

Java Stream: List of objects to HashMap without duplicates

From Dev

Using Objects as keys in Java HashMap

From Dev

Fetch list of objects in one list that are not part of another list using Java stream filter

From Dev

Using HashMap to store and retrieve objects in Java

From Dev

How to use java 8 streams to make a new list by using another's list objects values with filter?

From Dev

Using Java 8 lambda expressions, filter a List of objects by property of an inner list

From Dev

using dynamic linq to filter a list of objects

From Dev

intersection in java using hashmap or array list

From Dev

Filter a range without using an intermediate list

From Dev

In Java 7 or below, HOWTO filter a list of map objects using key/value found in the map

From Dev

In Java 7 or below, HOWTO filter a list of map objects using key/value found in the map

From Dev

How to map HashMap with Array List of Objects (list is the value in the hash map) into another HashMap using DozerBeanMapper?

From Dev

How merge list when combine two hashMap objects in Java

From Dev

java filter hashmap subset and sort its values without loosing entire hashmap

From Dev

Convert JSONArray to List<HashMap<String,Object>> in java without GSON

From Dev

how to filter a JavaRDD using a List using java

From Dev

JSON parsing without using Java objects

From Dev

java-8 filter a list without creating a new list

From Dev

List of objects inside a HashMap issue

From Dev

get list of Objects without using wrapped inner classes using Retrofit

From Dev

Filter array of objects using a list of desired key values

From Dev

Sorting Java List of objects using string date

From Dev

Count properties of objects in list using java 8

From Dev

grouping List of Objects and counting using Java collection

From Dev

filter list of objects by filtering a list of objects

From Dev

iterate a List<HashMap<String, String>> values using java

From Dev

Transform a flat list to domain objects with child objects using java streams

From Dev

Firebase - How to get list of objects without using AngularFire

Related Related

  1. 1

    Java Stream: List of objects to HashMap without duplicates

  2. 2

    Java Stream: List of objects to HashMap without duplicates

  3. 3

    Using Objects as keys in Java HashMap

  4. 4

    Fetch list of objects in one list that are not part of another list using Java stream filter

  5. 5

    Using HashMap to store and retrieve objects in Java

  6. 6

    How to use java 8 streams to make a new list by using another's list objects values with filter?

  7. 7

    Using Java 8 lambda expressions, filter a List of objects by property of an inner list

  8. 8

    using dynamic linq to filter a list of objects

  9. 9

    intersection in java using hashmap or array list

  10. 10

    Filter a range without using an intermediate list

  11. 11

    In Java 7 or below, HOWTO filter a list of map objects using key/value found in the map

  12. 12

    In Java 7 or below, HOWTO filter a list of map objects using key/value found in the map

  13. 13

    How to map HashMap with Array List of Objects (list is the value in the hash map) into another HashMap using DozerBeanMapper?

  14. 14

    How merge list when combine two hashMap objects in Java

  15. 15

    java filter hashmap subset and sort its values without loosing entire hashmap

  16. 16

    Convert JSONArray to List<HashMap<String,Object>> in java without GSON

  17. 17

    how to filter a JavaRDD using a List using java

  18. 18

    JSON parsing without using Java objects

  19. 19

    java-8 filter a list without creating a new list

  20. 20

    List of objects inside a HashMap issue

  21. 21

    get list of Objects without using wrapped inner classes using Retrofit

  22. 22

    Filter array of objects using a list of desired key values

  23. 23

    Sorting Java List of objects using string date

  24. 24

    Count properties of objects in list using java 8

  25. 25

    grouping List of Objects and counting using Java collection

  26. 26

    filter list of objects by filtering a list of objects

  27. 27

    iterate a List<HashMap<String, String>> values using java

  28. 28

    Transform a flat list to domain objects with child objects using java streams

  29. 29

    Firebase - How to get list of objects without using AngularFire

HotTag

Archive