hash set in java code example
Example 1: Javascript check for hash in URL
if (location.href.indexOf("#") != -1) {
}
Example 2: set in javascript
let mySet = new Set()
mySet.add(1)
mySet.add(5)
mySet.add(5)
mySet.add('some text')
let o = {a: 1, b: 2}
mySet.add(o)
mySet.add({a: 1, b: 2})
mySet.has(1)
mySet.has(3)
mySet.has(5)
mySet.has(Math.sqrt(25))
mySet.has('Some Text'.toLowerCase())
mySet.has(o)
mySet.size
mySet.delete(5)
mySet.has(5)
mySet.size
console.log(mySet)
Example 3: hashset in java
import java.util.HashSet;
public class HashSetForEach
{
public static void main(String[] args)
{
HashSet<String> hs = new HashSet<String>();
hs.add("Hello");
hs.add("world");
hs.add("Java");
for(String str : hs)
{
System.out.println(str);
}
}
}
Example 4: hashset in java
Let’s see java hashset example.
import java.util.HashSet;
public class HashSetExample
{
public static void main(String[] args)
{
HashSet<String> hs = new HashSet<>();
hs.add("Banana");
hs.add("Orange");
hs.add("Apple");
hs.add("Pineapple");
hs.add("Mango");
System.out.println(hs);
}
}
Example 5: java hashset
HashSet<String> hset = new HashSet<String>();
hset.add("Apple");
hset.add("Mango");
Example 6: what is hashset in java
- HashSet can have null, order is not guaranteed