How to convert array to LinkedHashSet

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;

public class ArrayToLinkedHashSet {

public static void main(String[] args) {

String [] arr ={“one”,”two”,”third”,”four”,”five”};

// make linkedhashset by arr (array of string)

Set<String> lhs = new LinkedHashSet<String>(Arrays.asList(arr));

// print linkedhashset

for (String str : lhs) {
System.out.println(” Element of lhs is=”+str);




Element of lhs is=one

Element of lhs is=two

Element of lhs is=third

Element of lhs is=four

Element of lhs is=five

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + 2 =