23.11.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 />

//HashMap<br />

Map m1 = new HashMap();<br />

m1.put("Zara", "8");<br />

m1.put("Mahnaz", "31");<br />

m1.put("Ayan", "12");<br />

m1.put("Daisy", "14");<br />

System.out.println();<br />

System.out.println(" Map Elements");<br />

System.out.print("\t" + m1);<br />

This will produce the following result:<br />

ArrayList Elements<br />

[Zara, Mahnaz, Ayan]<br />

LinkedList Elements<br />

[Zara, Mahnaz, Ayan]<br />

Set Elements<br />

[Zara, Mahnaz, Ayan]<br />

Map Elements<br />

{Mahnaz=31, Ayan=12, Daisy=14, Zara=8}<br />

The List Interface<br />

The List interface extends Collection and declares the behavior of a collection that stores<br />

a sequence of elements.<br />

<br />

<br />

<br />

<br />

Elements can be inserted or accessed by their position in the list, using a zerobased<br />

index.<br />

A list may contain duplicate elements.<br />

In addition to the methods defined by Collection, List defines some of its own,<br />

which are summarized in the following table.<br />

Several of the list methods will throw an UnsupportedOperationException if the<br />

collection cannot be modified, and a ClassCastException is generated when one<br />

object is incompatible with another.<br />

375

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

Saved successfully!

Ooh no, something went wrong!