Following is the code snippet I am working with.
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
ArrayList<StringBuffer> al = new ArrayList<StringBuffer>();
while (N-- > 0) {
str = new StringBuffer(sc.next());
if (al.contains(str)) {
System.out.println("Duplicate value " + str);
} else {
al.add(str);
}
}
If the input is: 4
abc
fgh
dfg
abc
It is showing blank output when the expected output is:
Duplicate value abc
Where am I going wrong here?
Anonymous User
22-Dec-2015