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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:37:01+00:00 2026-05-24T09:37:01+00:00

I need to shorten my char[] by one letter each time I pass through

  • 0

I need to shorten my char[] by one letter each time I pass through the code. The arguments I’m using are hello and hel. It should return true false false. At least that’s what I think it should return. I think what I have so far is close:

private void doDountSubStringMatchRecursive(String target, String key){
    char[] targetChar= target.toCharArray();//long one
    char[] keyChar= key.toCharArray();//short one
    for (int i = 0; i <=targetChar.length- keyChar.length; i++ ){
        System.out.println(testHelper(targetChar , keyChar));
        String recursive = targetChar.toString(); //Turns into a string
        targetChar = recursive.substring(1).toCharArray();//moves my string starting point over by one and converts the char[]
        System.out.println(targetChar.toString() + "  " +  keyChar.toString() );
    }
}


private boolean testHelper(char[] targetChar , char[] keyChar){
    boolean test = false;

    for (int i=0; i <= keyChar.length - 1; i++){ // runs through the char[] and states the test         
        if (keyChar[i] == targetChar[i]) {
            test =  true;
        } else {
            return false;
        }
    }
    return test;

}

And this is my output:

true
[C@24c21495  [C@41d5550d
false
[C@1cc2ea3f  [C@41d5550d
false
[C@40a0dcd9  [C@41d5550d
false
[C@1034bb5  [C@41d5550d
false
[C@7f5f5897  [C@41d5550d
false
[C@4cb162d5  [C@41d5550d
false
[C@11cfb549  [C@41d5550d
false
[C@5b86d4c1  [C@41d5550d
false
[C@70f9f9d8  [C@41d5550d

I don’t get what this is doing now. And yes I know I could just find occurrence of the key by using indexof(key).

  • 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-24T09:37:02+00:00Added an answer on May 24, 2026 at 9:37 am

    It’s not clear exactly what your code is supposed to do, as you haven’t really stated the problem very clearly. However, there is one bug that you should fix right away:

    targetChar.toString()
    

    does not do what you think it does. It gives you the String representation of the char array object (which is something like “C@24c21495”), not an interpretation of that array as a sequence of characters. If you want a String representing the sequence of characters in the array, then you want to call

    String.valueOf(targetChar)
    

    or

    new String(targetChar)
    

    to convert the char[] into a more helpful String.

    This change might help you debug the rest of your code.

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

Sidebar

Related Questions

I need to make a form similar to the one shorten link sites use.
I have a blog I wrote in PHP, and need to shorten the latest
I need some help. I am trying to shorten a full product name from
Need some regular expressions help. So far I have my code working to allow
I need to shorten this query and while I'm pretty good at SQL, I'm
Simple question, how do I shorten a call/name without using defines. For example, I
I have this piece of code that I would like to shorten... PackageManager p
I use a string: char word[100]; I add some chars to each position starting
Say we have a UTF-8 string $s and we need to shorten it so
I need to take a string, and shorten it to 140 characters. Currently I

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.