add(K): This method is available in java.util.LinkedHashSet class of Java.
Syntax:
boolean java.util.HashSet.add(K e)
This method takes one argument. This method adds the specified element to this set if it is not already present.
Parameters: One parameter is required for this method.
e: the element to be added to this set.
Returns: true if this set did not already contain the specified element.
Exceptions: NA
Approach
Java
import java.util.LinkedHashSet;public class LinkedHashSetadd {public static void main(String[] args) {LinkedHashSet<String> linkedHashSet =new LinkedHashSet<>();linkedHashSet.add("Hello");linkedHashSet.add("Java");System.out.println(linkedHashSet);}}
Output:
[Hello, Java]
No comments:
Post a Comment