About 31,700,000 results
Open links in new tab
  1. Set in Java - GeeksforGeeks

    Apr 8, 2025 · Operations on the Set Interface. The set interface allows the users to perform the basic mathematical operation on the set. Let’s take two arrays to understand these basic operations. Let set1 = [1, 3, 2, 4, 8, 9, 0] and set2 = [1, 3, 7, 5, 4, 0, 7, 5]. Then the possible operations on the sets are: 1.

  2. java - Getting an element from a Set - Stack Overflow

    Aug 19, 2016 · However if you're just looking for an ordered set, simply use SortedSet and its implementations, which are map-based (e.g. TreeSet allows for accessing first()). I miss that method, too, for exactly the same case you described …

  3. How to get first item from a java.util.Set? - Stack Overflow

    Dec 11, 2013 · Object firstElement = set.stream().findFirst().get(); And then you can do stuff with it straight away: set.stream().findFirst().ifPresent(<doStuffHere>); Or, if you want to provide an alternative in case the element is missing (my example returns new default string): set.stream().findFirst().orElse("Empty string");

  4. How to get an item from a Set in Java | Javarevisited - Medium

    Sep 25, 2023 · Since no get method exists on Set, the best we can do is either use an iterator and find the first element that matches based on equals, or to use the Stream API. Let’s see what both look like....

  5. Set Interface In Java: Java Set Tutorial With Examples

    Apr 1, 2025 · This Java Set Tutorial Explains All about the Set Interface in Java. It covers how to Iterate through a Set, Set Methods, Implementation, Set to List etc.

  6. Iterate Over a Set in Java - Baeldung

    May 11, 2024 · In this tutorial, we’ll take a look at how to iterate over elements of a Set and how it differs from the similar tasks on a List or array. 2. Getting Access to Elements in a Set

  7. Java Set: Guide to Managing Collections of Elements

    Oct 25, 2023 · To go through each element in a Set, you can use a for-each loop. Here’s an example: System.out.println(element); In this code block, we’re using a for-each loop to iterate over the Set and print each element. Understanding these basic operations is the first step to mastering Java Set.

  8. collections - Get an item from a Java Set - Stack Overflow

    So I can check if a particular ID is in the Set using Set.contains(new Object(ID)). However, having determined the object is in the set, I cannot get the object instance in the set. How can I get the exact object that the set contains? If you want to get from a collection you should use a Map. (Note most Set implementations are wrappers for a Map)

  9. Get an Element from a Set in Java | Java Tutorial - HatchJS.com

    Get element from set Java - Learn how to get an element from a set in Java with examples. Includes methods such as `.iterator()`, `.contains()`, and `.remove()`.

  10. Set in Java - Scientech Easy

    Jan 21, 2025 · Learn hierarchy of set in Java with example programs, set interface methods, set implementation, ways to create generic set object, set use

Refresh