I have this data class: ```data class AttachmentIt...
# getting-started
j
I have this data class:
Copy code
data class AttachmentItem(val imageId: String, val extension: String)
now I have two lists of these attachments:
Copy code
val list1 = listOf<AttachmentItem>()
val list2 = listOf<AttachmentItem>()
//now I want to know which AttachmentItems are missing in list1 but are there in list 2 and vice versa. So:
val diff1 = //attachments available in list1 but not in list2
val diff2 = //attachments available in list2 but not in list1
How would I do that in kotlin?
j
diff1 = list1 - list2
m
what Jacob said. Although, if you work with data classes you might be wanting to type list1 and list2 as sets instead, guarantees uniqueness (why would you have two images with the same ID and extension?) and makes the difference checks of
set1 - set2
and
set2 - set1
as fast as possible
j
okay thanks