Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5975855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:08:43+00:00 2026-05-22T21:08:43+00:00

If I have an unordered character array, how can I get the unique elements?

  • 0

If I have an unordered character array, how can I get the unique elements?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:08:44+00:00Added an answer on May 22, 2026 at 9:08 pm

    One-liner:

    Set<Character> uniqueChars = new HashSet<Character>(Arrays.asList(array));
    

    (the array will need to be Character[] not char[]. Otherwise you’d have to convert it to the wrapper array)

    Note that, if this is homework, you would need a more algorithmic approach in order to show that you understand what you are doing. The above solution may not be applicable. But here’s how it works:

    • the array is turned into a List. This is O(1), as the array just backs the new, unmodifiable list. This is done so that the array can conform the the List interface, which is required by the HashSet constructor
    • a HashSet is a collection backed by a HashMap (hashtable). It computes the hashes of keys and stores them in an internal array, under an index = hash. Thus lookup is O(1).
    • the HashSet constructor simply iterates the passed List and calls add(..) for each item. Items that are the same are not allowed twice in the set (sets by definition do not allow duplicates). This is so, because the hash of the item will be the same as an existing one, so the new one will replace the old one. Note that items with the same hash are allowed, but not those that are also equal (.equals(..))
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an unordered list with elements and I want to append an item
I have an unordered tree. Each node represents a task that can be done
I have an unordered list with a few list elements. #tags { width: 300px;
I have an unordered list of form elements with ids <ul class=sortable id=userForm> <li
I have unordered list of links and i am trying to get the clicked
I have an unordered array of instances of the following class: @interface Place :
I have an unordered array with instances of the following class: @interface Place :
I have three unordered lists that have been created as Scriptaculous Sortables so that
I have this unordered list <ul> <li>two</li> <li>three</li> </ul> Is there a way I
I have an unordered list <ul id=List1> <li>www.xyz.com</li> <li>www.abc.com</li> </ul> using jquery, I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.