Search Java Code Snippets

  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.

#Java - Code Snippets for '#List of objects' - 3 code snippet(s) found

 Sample 1. Method to remove duplicates from a Map ( string and List of objects ) by matching the member field of the object.

Map<String,List<ClassInfoBean>> removeDuplicates(Map<String, List<ClassInfoBean>> interfaceMap){
   Map<String, List<ClassInfoBean>> interfaceMapWithoutDuplicate = new HashMap();
   for(Map.Entry<String, List<ClassInfoBean>> entry: interfaceMap.entrySet()){
      List<ClassInfoBean> classListWithoutDuplicate = new ArrayList();
      boolean alreadyContain = false;
      for(ClassInfoBean classes: entry.getValue()){
         for(ClassInfoBean classes1: classListWithoutDuplicate){
               alreadyContain = true;
         if(alreadyContain == false){
      interfaceMapWithoutDuplicate.put(entry.getKey(), classListWithoutDuplicate);
   return interfaceMapWithoutDuplicate;

   Like      Feedback     map  map of list of objects  remove duplicates from map  Map.Entry

 Sample 2. Method to remove duplicates from a List of objects by matching the member elements of objects.

List<ClassInfoBean> removeDuplicates(List<ClassInfoBean> listClassInfo){
   Set<ClassInfoBean> set = new HashSet();
   Set<String> url = new HashSet();
   boolean flag = false;
   for(ClassInfoBean cl: listClassInfo){
   return new ArrayList(set);

   Like      Feedback     list  list of objects  remove duplicates from list

 Sample 3. Given a list of File objects, sort them by their name

public List sortFiles(List<File> files) {
files.sort(new Comparator<File>() {
public int compare(File file1, File file2) {
return file1.getName().compareTo(file2.getName());

return files.

   Like      Feedback     file

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner