toString(): This method is available in java.util.LinkedHashSet class of Java.
Syntax:
String java.util.AbstractCollection.toString()
This method returns a string representation of this collection.
Parameters: NA
Returns: a string representation of this collection.
Exceptions: NA
Approach
Java
import java.util.LinkedHashSet;public class LinkedHashSettoString {public static void main(String[] args) {LinkedHashSet<String> linkedHashSet =new LinkedHashSet<>();linkedHashSet.add("Hello");linkedHashSet.add("Java");System.out.println(linkedHashSet.toString());}}
Output:
[Hello, Java]
No comments:
Post a Comment