Java eliminates duplicates in list

Source: Internet
Author: User

Import java.util.arraylist;import java.util.hashset;import java.util.list;public class  removerepart {    public static void main (String[] args)  {        List<String> list = new  Arraylist<string> ();         list.add ("Zhang San");         list.add ("Zhang 31");         list.add ("Zhang 32");         list.add ("Zhang San");         list.add ("Zhang 31");         list.add ("Zhang 32");                 //Method One          for  (Int i = 0; i < list.size ();  i++)  {       &nBsp;     system.out.println ("Native list:" +list.get (i));         }        //Method Two          hashset h = new hashset (list);         System.out.println ("Put list in HashSet:" +h)   //[Zhang San,  Zhang San 1,  Zhang San 2]         list.clear ();          system.out.println (" List call Clear () after: "+list);   //[]        list.addall (h);  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("Processed list:" +list);   //[Zhang San,  Zhang 31,   Zhang San 2]    }}


This article is from the "Monkey Crazy" blog, make sure to keep this source http://1251769215.blog.51cto.com/11633863/1783727

Java eliminates duplicates in list

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.