Java Collection Common traversal

Source: Internet
Author: User

Dfdfd

package host;import java.util.*;import com.sun.media.jfxmedia.events.newframeevent;public  Class main {public static void main (string[] args)  {arraylist a=new  arraylist (); a.cadd (666); a.cprint ();     llinkedlist b=new llinkedlist (); B.ladd (777); b.lprint (); sset c=new sset ();     c.sadd (0); c.sprint (); mmap m= New mmap (); m.madd (9,  "water and electricity bill"); m.mprint ();}} Class arraylist{private list<integer> clist;public arraylist () {cList = new  LinkedList<Integer> (); clist.add (2); clist.add (3); clist.add (4); clist.add (5); clist.add (6);} Public void cadd (int i) {clist.add (i);} for  (integer integer : clist)  {//system.out.println (Integer);//}//system.exit (0); Public void cprint () {for  (iterator<integer> iterator = clist.iterator ();  iterator.hasnext ();)  {//integer integer =  (Integer)  iterator.next (); System.out.println (iterator.next ());}}} Class llinkedlist{private linkedlist< integer> llinkedlist;public llinkedlist ()  {// TODO Auto-generated constructor stubllinkedlist=new LinkedList<> (); Llinkedlist.add (llinkedlist.add); llinkedlist.add; llinkedlist.add (16); llinkedlist.add (+); Public void ladd (int n)  {llinkedlist.add (n);} Public void lprint ()  {for  (integer in : llinkedlist)  { System.out.println (in);}} Class sset{private set<integer> cset;public sset ()  {// TODO  auto-generated constructor stubcset = new treeset<> (cSet.add); CSet.add (31) ; Cset.add (98); cset.add (+); cset.add (5); cset.add (2); cset.add (14);} Public void sadd (integer n)  {cset.add (n);} Public void sprint ()  {iterator<intEger> it=cset.iterator ();while  (it.hasnext ())  {Integer ii =  (Integer)   It.next (); System.out.println (ii);}}} Class mmap{private map<integer, string> cmap;public mmap ()  {// TODO  Auto-generated constructor stubcMap=new HashMap<> (); cmap.put (1,  "gdgdgdf"); Cmap.put (2,  "dfgdfg451"), cmap.put (3,  "qeqwejh4"), cmap.put (4,  "ouiopipio"), cmap.put (5,  ", MLJKB ");} Public void madd (int n,string s)  {cmap.put (n, s);} Public void mprint ()  {for  (iterator<map.entry<integer, string>> ents  = cmap.entryset (). iterator ();  ents.hasnext ();)  {Map.Entry<Integer, String>  ent = ents.next (); System.out.println (ent.getkey () + "---" +ent.getvalue ());}}


Java Collection Common traversal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.