Android Question How to identify duplicate elements in a list, from code

WebQuest

Active Member
Licensed User
Hello Community.
I can't identify via a comparison if there are equal elements in a list.

Which is a simple code to identify the duplicate and remove it from the list?.
B4A:
(ArrayList) [0, 1, 2, 3, 4, 5, 9, 17, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 35, 36, 36, 37, 38, 38, 38, 39, 39, 39, 40, 41, 41, 41, 42, 43, 45, 46, 50, 50, 50, 50]
 

johnmie

Active Member
Licensed User
Longtime User
As unsophisticated hobby programmer I simply use
killDuplis:
List1.sort(true)
for i = list1.size-1 to 1 step -1
if list1.get(i) = list1.get(i-1) then
     list1.remove(i)
next
 
Upvote 0

emexes

Expert
Licensed User
As unsophisticated hobby programmer I simply use
killDuplis:
List1.sort(true)
for i = list1.size-1 to 1 step -1
if list1.get(i) = list1.get(i-1) then
     list1.remove(i)
next

Is there any conscious reasoning behind the equality operator being honoured with surrounding spaces, but the subtraction operator not?

No problem; just curious. ?
 
Upvote 0

johnmie

Active Member
Licensed User
Longtime User
Is there any conscious reasoning behind the equality operator being honoured with surrounding spaces, but the subtraction operator not?

No problem; just curious. ?
No, just an old habit.
But tell me, does this code adequately solve the problem and/or is it slower than working with objects or B4Xsets?
 
Upvote 0

emexes

Expert
Licensed User
But tell me, does this code adequately solve the problem

Looked very good to me ? after I wrapped my head around that it wasn't being tripped up by deleted (and now "missing") duplicates.

I haven't actually tested it because my previous laptop died last week and I have yet to install B4X onto its replacement.
 
Upvote 0
Top