addMapEntry to index 0
Moderator: Martin
addMapEntry to index 0
Is it possible to addMapEntry to index 0 that is beginning of map?
Re: addMapEntry to index 0
There is no direct function to do that. There is no also technical necessity to sort it too, since map values always work based on key-value mapping. So this is purely for aesthetic. I also wish to sort similar key together.
To insert at 0 index, the fastest way is using addAllMapEntries(). Create a temporary map of the key-value you wanna add, and add the original map to it.
However it seems removeVariable(addmap) doesn't work properly in this 1.34.0 version. The addmap variable still shows up at debug dialog. Is it just me?
Sorting the map or inserting at index other than 0 can be done too, with extra effort. Even manual sorting is also possible, but more troublesome.
To insert at 0 index, the fastest way is using addAllMapEntries(). Create a temporary map of the key-value you wanna add, and add the original map to it.
Code: Select all
realmap = newMapFromValues(
"key1", "value1",
"key2", "value2");
addmap = newMapFromValues("key0", "value0"); // key value to be inserted
addAllMapEntries(addmap, realmap);
realmap = addmap;
removeVariable(addmap);
Sorting the map or inserting at index other than 0 can be done too, with extra effort. Even manual sorting is also possible, but more troublesome.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: addMapEntry to index 0
This is the way to do it (include it in double quotes. Kind of annoying 
removeVariable("addmap")

removeVariable("addmap")
Re: addMapEntry to index 0
Thanks for the tip.
I just use this removeVariable() the first time, even though i have seen it several times in others' flow. Double quote is fine, since sometimes we want to dynamically remove other variable.
I just proof the manual sorting is possible, and has made the flow to sort my glovar. Not a very important flow, but a nice exercise.

I just proof the manual sorting is possible, and has made the flow to sort my glovar. Not a very important flow, but a nice exercise.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.