So basically I’ve 2 lists:
val list = context.packageManager.getInstalledPackages(0);
var listOfAvs: MutableList<String> = arrayListOf(
"com.app1",
"com.app2"
)
I want to find common elements between the 2 lists.
To make both same kind of list I wrote this code
val listMuted: MutableList<String> = arrayListOf()
var counter = 0
for(apks in list)
{
listMuted.add(apks.packageName.toString())
}
I can’t really figure out how to match common elements between both lists.
I’m not here writing the code as I made like tens of different functions trying to do that but all of them failed.
Please help I’m since a month trying to achieve it
3
Answers
Working Code with small adjustment, thanks LEE!! :-) appreciate man
I add some comment between the codes. If you have any question, please comment.
There is an
intersect
function that makes this really easy. You can usemap
to pull the Strings out of the list of PackageInfo.If you need them in a list you can call
toList()
ortoMutableList()
on this result.