I had a list
and each item of the list has its parent id
. I created hashmap
which contain list item
as per its parentId
. The list is in proper sequence and I add item
to hashmap
. In the end, the hashmap sequence changed. I don't know where.
var package = HashMap<String, MutableList<Model>>()
var temp: MutableList<Model>? = ArrayList<Model>()
for (item in list!!) {
temp = package?.get(item.parentId!!)
Log.e("parent id",Gson().toJson(item.parentId!!))
if (temp != null)
temp.add(item)
else {
temp = ArrayList<Model>()
temp.add(item)
}
package?.put(item.parentId!!, temp)
Log.e("package",Gson().toJson(package.keys))