Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

hashset java

// Java program to demonstrate working of HashSet
import java.util.*;
  
class HashSetDemo {
  
    // Main Method
    public static void main(String[] args)
    {
        HashSet<String> h = new HashSet<String>();
  
        // Adding elements into HashSet usind add()
        h.add("India");
        h.add("Australia");
        h.add("South Africa");
        h.add("India"); // adding duplicate elements
  
        // Displaying the HashSet
        System.out.println(h);
        System.out.println("List contains India or not:"
                           + h.contains("India"));
  
        // Removing items from HashSet using remove()
        h.remove("Australia");
        System.out.println("List after removing Australia:"
                           + h);
  
        // Iterating over hash set items
        System.out.println("Iterating over list:");
        Iterator<String> i = h.iterator();
        while (i.hasNext())
            System.out.println(i.next());
    }
}
Comment

hashset java

HashSet<Integer> set = new HashSet<>();
set.add(1);
set.add(2);

if(set.contains(1)){
  print("hashset contains 1");
}
else{
   print("hashset doesn't contain 1");
}
//output
hashset contains 1
Comment

example of HashSet

Set<String> set = new HashSet<String>(list);
Comment

Java Creating a HashSet

// HashSet with 8 capacity and 0.75 load factor
HashSet<Integer> numbers = new HashSet<>(8, 0.75);
Comment

PREVIOUS NEXT
Code Example
Java :: Adding Entire ArrayList to another ArrayList in Java 
Java :: super class tostring java 
Java :: terminate function calling in java 
Java :: java float data type 
Java :: finalize method 
Java :: switch in java 
Java :: java create a string 
Java :: How to Initialize Arrays in Java? 
Java :: array to array list java 
Java :: How to perform in-order traversal of a binary tree? 
Java :: insert node at end of doubly linked list 
Java :: java hashmap 
Java :: what is return method 
Java :: Java forEach() Method 
Java :: calculating the percentile in java 
Java :: mcq java 
Java :: Load array of strings from console 
Java :: writeToFileAsync java 
Java :: if else bedingungen java 
Java :: java regex of eauations 
Java :: jbutton actionperformed 
Java :: Android Studio First time run check 
Java :: list in list 
Java :: close current file android studio shortct 
Java :: string to integer online 
Java :: calculate tip and sales tax function 
Java :: leap year java method 
Java :: unparseable date android 
Java :: android int color = ContextCompat.getColor(getContext(), mColorResourceId); 
Java :: how to stop scanner object skipping 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =