25.02.2017 Views

java_tutorial

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java<br />

}<br />

};<br />

Thread t = new Thread(runner);<br />

t.start();<br />

System.out.println("Main waiting");<br />

try {<br />

t.join();<br />

} catch (InterruptedException ignored) {<br />

}<br />

}<br />

This will produce the following result:<br />

ain waiting<br />

Thread waiting<br />

If you do not include the call to System.gc(), the system may never run the garbage<br />

collector as not much memory is used by the program. For a more active program, the<br />

call would be unnecessary.<br />

The LinkedHashMap Class<br />

This class extends HashMap and maintains a linked list of the entries in the map, in the<br />

order in which they were inserted. This allows insertion-order iteration over the map. That<br />

is, when iterating a LinkedHashMap, the elements will be returned in the order in which<br />

they were inserted.<br />

You can also create a LinkedHashMap that returns its elements in the order in which they<br />

were last accessed.<br />

Following is the list of constructors supported by the LinkedHashMap class.<br />

Sr.<br />

No.<br />

Constructors and Description<br />

1<br />

LinkedHashMap( )<br />

This constructor constructs a default LinkedHashMap.<br />

LinkedHashMap(Map m)<br />

2<br />

This constructor initializes the LinkedHashMap with the elements from the<br />

given Map class m.<br />

415

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!