package?com.neuedu.list;?import?java.util.HashSet;import?java.util.Iterator;?public?class?HashSetOutputDemo?{ public?static?void?main(String[]?args)?{ HashSet?h?=?new?HashSet(); h.add("1"); h.add("2"); h.add("3"); h.add("4"); h.add("1");//set不可重復(fù),覆蓋 //1、 System.out.print(h);//默認(rèn)調(diào)用toString System.out.println("n----------------------"); //2、 for?(Object?object?:?h)?{ System.out.print(object); } System.out.println("n----------------------"); //3、 Iterator?i?=?h.iterator(); while(i.hasNext()){ System.out.print(i.next()); } System.out.println("n----------------------"); }}
以上就是北大青鳥(niǎo)長(zhǎng)沙麓谷校區(qū)java培訓(xùn)機(jī)構(gòu)的小編針對(duì)“Java hashset輸出的三種方式”的內(nèi)容進(jìn)行的回答,希望對(duì)大家有所幫助,如有疑問(wèn),請(qǐng)?jiān)诰€咨詢,有專業(yè)老師隨時(shí)為你服務(wù)。