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

  • Home
  • SEARCH
  • 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 6622135
In Process

The Archive Base Latest Questions

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

I am doing an application where I want to find a specific char in

  • 0

I am doing an application where I want to find a specific char in an array of chars. In other words, I have the following char array:

char[] charArray= new char[] {'\uE001', '\uE002', '\uE003', '\uE004', '\uE005', '\uE006', '\uE007', '\uE008', '\uE009'};

At some point, I want to check if the character '\uE002' exists in the charArray. My method was to make a loop on every character in the charArray and find if it exists.

for (int z = 0 ; z < charArray; z ++) {
    if (charArray[z] == myChar) {
        //Do the work
    }
}

Is there any other solution than making a char array and finding the character by looping every single char?

  • 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-25T21:22:04+00:00Added an answer on May 25, 2026 at 9:22 pm

    One option is to pre-sort charArray and use Arrays.binarySearch(charArray, myChar). A non-negative return value will indicate that myChar is present in charArray.

    char[] charArray = new char[] {'\uE001', '\uE002', '\uE003', '\uE004', '\uE005', '\uE006', '\uE007', '\uE008', '\uE009'};
    Arrays.sort(charArray); // can be omitted if you know that the values are already sorted
    ...
    if (Arrays.binarySearch(charArray, myChar) >= 0) {
      // Do the work
    }
    

    edit An alternative that avoids using the Arrays module is to put the characters into a string (at initialization time) and then use String.indexOf():

    String chars = "\uE001...";
    ...
    if (chars.indexOf(myChar) >= 0) {
       // Do the work
    }
    

    This is not hugely different to what you’re doing already, except that it requires less code.

    If n is the size of charArray, the first solution is O(log n) whereas the second one is O(n).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam doing one application .In that i want to find out the x,y,z axis
I am doing a movieplayer application and I want to activate certain settings about
I'm doing a kinect Application using Kinect SDK . The Result I want that
I want to preserve a property between postbacks in an ASP.Net application. Currently doing
I am doing an application in Yii Framework.I have progressed to some way like
Now I am doing an application.In my app I have to change textview value
Can somebody help me find the mistake I am doing in evaluating following XPath
I am doing a file search and replace for occurrences of specific words in
I'm working on a windows form application and I want to have a rich
For a project I am doing, I want the Mac application to accept plug-ins.

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.