Eg I have a List of objects, List A, and its initialized with 7 elements. Each element is ordered by an integer field called "elementOrder".
How can I take a new List of the same objects, List B, and merge them into List A based on the "elementOrder"?
Note that List B contains duplicates of List A and I only want to merge unique elements of List B into List A.
Thanks you. S
//copy ListA element on a new list
var newList = new ArrayList<ElementType>(ListA)
//add B elements to new list
newList.addAll(ListB)
//order the new list with elementOrder column
newList = newList.orderBy( \ element -> element.elementOrder)
Q : List B contains duplicates of List A and I only want to merge unique elements of List B into List A
R : you must use Blocks (lambda expressions) to filter duplicates elements
//copy ListA element on a new list
var newList = new ArrayList<ElementType>(ListA)
//filter B elements not in ListA
var FiltredListB = ListB.where( \ element -> not ListA.contains(element))
//add FiltredListB elements to new list
newList.addAll(FiltredListB)
//order the new list with elementOrder column
newList = newList.orderBy( \ element -> element.elementOrder)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.