About 24,000,000 results
Open links in new tab
  1. How to Get Elements By Index from HashSet in Java?

    Jan 28, 2021 · The three different ways we can get elements by index in a HashSet is by: Method 1: Using Array. Access elements by index. import..; .(); ..(); String[] .(new String[.()]); ..( Method …

  2. Java: Retrieving an element from a HashSet - Stack Overflow

    Aug 18, 2012 · Use HashSet as you wanted, then: public Object getObjectReference(HashSet<Xobject> set, Xobject obj) { if (set.contains(obj)) { for (Xobject o …

  3. java - How to obtain index of a given LinkedHashSet element …

    Here is an implementation that does insertions, removals, retainings, backed by an arraylist to achieve o(1) on get(index).

  4. java - Get an item by index from the HashSet array and also …

    Oct 4, 2014 · In HashSet you won't be able to find value by index. If you still want to find the element you have no other option but to use the iterator, it will iterate through the Hashset and …

  5. How to Print HashSet Elements in Java? - GeeksforGeeks

    Jan 9, 2023 · We can use 2 ways to print HashSet elements: Using the iterator () method to traverse the set elements and printing it. Directly printing it using a reference variable. Method …

  6. Java HashSet - GeeksforGeeks

    Mar 12, 2025 · You must be wondering that to enter a value in HashMap we need a key-value pair, but in HashSet, we are passing only one value. Storage in HashMap: Actually the value …

  7. How to get value from HashSet in Java? - Namso gen

    Apr 8, 2024 · To retrieve values from a HashSet, we can use methods like the contains() method to check if a value is present, or use iteration to access and process each element. HashSet …

  8. index of character in hashset Java - Stack Overflow

    Oct 24, 2018 · How do I get the index of element in HashSet when using java? Let's say HashSet<Character> hs = new HashSet<Character>(); hs.add('s'); hs.add('t'); hs.add('a'); …

  9. How to Get Index of an Item in Java Set | Baeldung

    Jan 8, 2024 · In this tutorial, we’re going to look at how we can get the index of an item in a Java Set. Sets in Java don’t allow duplicate elements, and some important implementations of the …

  10. Java Program to Get First or Last Elements from HashSet

    Sep 5, 2023 · Method 2: Using streams to find the first element in HashSet, with the help of the findFirst() and get() methods in Java. Syntax: set.stream().findFirst().get()

Refresh