Java aggregation experience (1)

xiaoxiao2021-03-06  73

1.hashmap traversal method one:

Map map

=

New

Hashmap (); item iter

=

Map.EnTryset (). iterator ();

While

(ore.hasnext ())

{Map.Entry Entry = (Map.Entry) iter.next (); Object Key = entry.getKey (); object val = entry.getValue ();

Method 2:

Map map

=

New

Hashmap (); item iter

=

Map.keyset (). iterator ();

While

(ore.hasnext ())

{Object Key = iter.next (); Object Val = map.get (key);

The way one is usually more efficient than the way. 2. Java gathering selection

If you are involved in stack, queue, etc., you should consider using List, for quick plug, delete elements, you should use LinkedList, if you need to quickly access elements, you should use ArrayList. If the program is in a single threaded environment, or the access is only in one thread, considering the non-synchronous class, its efficiency is high, if multiple threads may operate a class at the same time, the synchronous class should be used. Pay special attention to the operation of the hash table, as a key to Key, to properly reply Equals and HashCode methods. Try to return to the interface instead of the actual type, if you returns List instead of arraylist, the client code does not have to change when you need to change ArrayList to linkedList. This is for abstract programming.

转载请注明原文地址:https://www.9cbs.com/read-93024.html

New Post(0)