StringBufferdoes not override Object equals, so when you search if your Listcontains a specific instance StringBuffer, you check to see if the exact link is displayed in List.
You can use HashSet<String>to avoid duplicates, because it Stringoverrides equals, and then (if necessary) create List<StringBuffer>from elements HashSet.
BTW, StringBuilder , StringBuffer ( , ).
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
ArrayList<StringBuffer> al = new ArrayList<StringBuffer>();
Set<String> uniques = new HashSet<>();
while (N-- > 0) {
uniques.add(sc.next());
}
for (String s : uniques)
al.add (new StringBuffer(s));
, :
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
ArrayList<StringBuffer> al = new ArrayList<StringBuffer>();
Set<String> uniques = new HashSet<>();
while (N-- > 0) {
String str = sc.next();
if (!uniques.add(str))
System.out.println("Duplicate value " + str);
}
for (String s : uniques)
al.add (new StringBuffer(s));