Java uses Hashtable to filter duplicate values in an array _java

Source: Internet
Author: User

The example in this article describes how Java uses Hashtable to filter duplicate values in an array. Share to everyone for your reference, specific as follows:

Package org.eline.core.web.support;
Import java.util.Hashtable; /***************************** * * * @author ZDW * */public class Objectfilter {public static void main (string[) args
  {//String test string arr[] = {"13111", "13112", "13111"};
  Objectfilter SF = new Objectfilter ();
  Object results[] = Sf.filter (arr);
  System.out.println (results.length);
  for (int i = 0; i < results.length ++i) {System.out.println (results[i]);
  //plastic test integer arr2[] = {1, 3, 5, 7, 1, 2, 4, 5};
  Object results2[] = Sf.filter (ARR2);
  for (int i = 0; i < results2.length ++i) {System.out.println (results2[i]);  /************************* * Filtering Method * * @param arr * to filter array * @return/public object[] Filter (Object
  Arr[]) {hashtable<object, object> Hashtable = new Hashtable<object, object> ();
  for (int i = 0; i < arr.length ++i) {hashtable.put (Arr[i], arr[i]);
  Object results[] = null; Results = HASHTABLE.VAlues (). ToArray ();
 return results;

 }
}

More about Java-related content readers can view the site topics: "Java Data structure and algorithm tutorial", "Java Operation DOM node skills summary", "Java file and directory operation tips Summary" and "Java Cache operation Tips"

I hope this article will help you with Java programming.

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.