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 4007942
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:41:35+00:00 2026-05-20T08:41:35+00:00

Sorry if this is a repeat, but I’ve been looking for an answer to

  • 0

Sorry if this is a repeat, but I’ve been looking for an answer to this question, but I can’t find one anywhere and my last question was for the same code but with a different problem.

I need to find a string inside an array, but all the Strings in the array are 16 characters long and the search key will not be 16 characters when entered by the user. Every attempt I’ve made at this thus far has ended with the String not being found, though I know it is in the array. I think it has something to do with the trailing spaces after the actual string text in the array, but I’m not sure how to handle it.

This is my search statement so far. I’ll note that my compareTo() statement does compare this.name to other.name, so I’m quite confused.:

case 'b':
      System.out.println();
      System.out.println("Please enter a customer name:");

      String search = kb.nextLine(); //read the user's search
      int place; //location of result

      Arrays.sort(A);

      Customer searchCust = new Customer(search);

      place = Arrays.binarySearch(A,searchCust);

      if (place <= 0)
        System.out.println("Cannot find customer named " + search);
     else
     {
       System.out.println("Customer found:");  
       System.out.println(A[place-1]);
        break;


 public int compareTo(Customer a)
 {
  return this.name.compareTo(a.name);
 }   //end compareTo
  • 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-20T08:41:36+00:00Added an answer on May 20, 2026 at 8:41 am

    Edit: after clarification of the question.

    So, the problem is that your users are entering something like

    "Smith"

    but your array elements are always padded to 16-characters long and might have the search term somewhere in the middle, like

    "John Smith      "

    then I would recommend just looping through the array and doing a .contains() on each element.

    Binary search is an optimization which I would only consider if performance shows itself to be a problem, because it introduces quite a lot of complication.

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

Sidebar

Related Questions

My text animation works perfectly, but doesn't repeat. How do I get this to
Sorry about the vocabulary question, but I'm writing my master thesis and it's a
This could easily be done using code, but I wondered if it could be
I know this is a pretty well posted thing to do, but I still
Using Ruby on Rails, how can I achieve a polymorphic has_many relationship where the
thanks for help, ended up with this html{ position:relative; min-width:950px; height:100%; background:black url(images/GrassBG.png) repeat-y
This is what I'd like my workflow to look like at a conceptual level:
Sorry for the long explanation. Thanks in advance to all who are taking their
Supposing I'm setting a background image for a web page in CSS like this:
I have a JScrollPane that holds a JLabel using the following code: //Create TEXT

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.