I found this code which was meant to avoid duplicate values for numbers so I changed it to consider String elements.It successfully avoids duplicate names when printing, but it does not sort the names in alphabetic order.
I also hope that it does not print a specific element "vacant", because it will be later updated with a name through an input.
This is based on a booking system to sort names in ascending order,so empty elements are called "vacant".
Please can someone help me.
String[] a ={"Anne","Anne","Afrid","vacant","vacant","Sammy","Dora","vacant"};
HashSet<String> nameSet = new HashSet<>();
for (int i = 0; i < a.length;i++){
nameSet.add(a[i]);
}
for (String name: nameSet) {
System.out.println(name+" ");
}