
Hi dear
I have a problem, please solve it,please give me solution within 1-2 days.I am a Student,MCA. ie I want to pass a list to a method and within method definition i removed the duplicate elements and when i returned the list to the calling method.when i compiled the code ,an errors occurs that is:
removeDuplicateFromArraListByMethod.java:21:<identifier> expected public String showNonDuplicateElements(list1)
---------------Below is my code, I tried---------------------
import java.util.*;
public class removeDuplicateFromArraListByMethod
{
public static void main(String args[]) throws Exception
{
nonDuplicateFound ob=new nonDuplicateFound();
ArrayList<String>list=new ArrayList<String>();
list.add("A");
list.add("A");
list.add("A");
list.add("B");
list.add("B");
list.add("C");
ArrayList list3= ob.showNonDuplicateElements(list);
for(Object item:List3)
System.out.println(item);
}
} class nonDuplicateFound
{
public String showNonDuplicateElements(list1)
{
HashSet set=new HashSet(list1);
ArrayList newList=new ArrayList(set);
Collections.sort(newList);
return newList;
}
}
kindly solve my problem and send to <m.kumara.mca@gmail.com>
Thanks & Regards
Manoj
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.