0

Did a bunch of searching but came up blank. I'm using GreenDao within my app and am querying my database in a specific method which results in a list. I'd like to convert that list to a copyonwritearrayset. Is there a simple way to do this that I'm just not seeing?

At this point the only thing I can think to do is go item by item in a for loop:

List<Item> list = mItemDao.queryBuilder().orderDesc(ItemDao.Properties._id)
                    .list();
            CopyOnWriteArraySet<Item> set = new CopyOnWriteArraySet<Item>();

            for (Item item : list) {
                set.add(item);
            }
return set;
Psest328
  • 6,575
  • 11
  • 55
  • 90
  • possible duplicate of [Easiest way to convert a List to a Set? - Java](http://stackoverflow.com/questions/1429860/easiest-way-to-convert-a-list-to-a-set-java) – m0skit0 May 03 '14 at 19:29
  • 1
    @m0ski0 it's definitely a duplicate :) When I searched, I couldn't find anything, but when I posted, that link came up as a related question. – Psest328 May 03 '14 at 19:32

2 Answers2

0

What about Collection<E>#addAll(Collection<? extends E>)

set.addAll(list)
m0skit0
  • 25,268
  • 11
  • 79
  • 127
  • That works. I'm posting another answer I found as soon as I submitted the question, lol. I'm giving you the check because this is a working answer :) – Psest328 May 03 '14 at 19:28
0

All my searching turned up nothing, but once I posted the question, one of the related links that came up was the exact same question I had. I'm going to go bang my head against the wall and move on.

Here's the answer to my question:

Easiest way to convert a List to a Set in Java

Community
  • 1
  • 1
Psest328
  • 6,575
  • 11
  • 55
  • 90