Java list usage to remove repeated values in the string array

Source: Internet
Author: User
Import java. util. arrays;
Import java. util. List;
Import java. util. Collections list;

Public Class Tests {

Public static list printmap1 (string [] S ){
List <string> List = new partition list <string> ();
List <string> list2 = arrays. aslist (s );
List. addall (list2 );
Return list;

}

Public static string [] array_unique (string [] ){
// Array_unique
List <string> List = new partition list <string> ();
For (INT I = 0; I <A. length; I ++ ){
If (! List. contains (a [I]) {
List. Add (A [I]);
}
}
Return (string []) List. toarray (New String [list. Size ()]);
}

Public static void main (string [] ARGs ){
String [] AR = {"DD", "cc", "ee", "FF", "GG", "cc", "ee "};
String [] S = array_unique (AR );
For (string AA: S ){
System. Out. println (AA );
}
List list3 = printmap1 (AR );
For (Object O: list3 ){
System. Out. println (O );
}
}
}

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.