android - How to use a ArrayMap randomly -


i wrote following arraymap:

arraymap<sprite,string> arraymap = new arraymap<sprite, string>();         arraymap.put(sprite, "rot");         arraymap.put(sprite1, "braun");         arraymap.put(sprite2, "dunkelblau");         arraymap.put(sprite3, "dunkelgrün");         arraymap.put(sprite4, "gelb");         arraymap.put(sprite5, "hellblau");         arraymap.put(sprite6, "hellgrün");         arraymap.put(sprite7, "lila");         arraymap.put(sprite8, "orange");         arraymap.put(sprite9, "rosa"); 

now want show randomly 4 of these sprites on screen of device. however, don´t know how use arraymap , decide (randomly) sprites drawn. hope can me.

about when use arraymap according android documentation:

note implementation not intended appropriate data structures may contain large numbers of items. slower traditional hashmap, since lookups require binary search , adds , removes require inserting , deleting entries in array. containers holding hundreds of items, performance difference not significant, less 50%.

using collections.shuffle():

    arraylist<sprite> keys = new arraylist(arraymap.keyset());     collections.shuffle(keys);     (int = 0; < 4; i++) {         sprite key = keys.get(i);         string value = arraymap.get(key);     } 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -