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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:49:10+00:00 2026-05-17T20:49:10+00:00

Here’s where I wish Java’s String class had a replaceLast method, bu it doesn’t

  • 0

Here’s where I wish Java’s String class had a replaceLast method, bu it doesn’t and I’m getting the wrong results with my code.

I’m writing a program that searches a data structure for any items that match a string prefix. However, since I’m using an Iterator, the last item returned by the iter.next() call doesn’t match the pattern, so I want to change the search string so that the last character of the query is increased by one letter. My testing code is returning [C@b82368 with this code and An as titleSearch:

public String changeLastCharacter(String titleSearch) {
    char[] temp= titleSearch.toCharArray();

    char lastLetter= temp[temp.length-1];
    lastLetter++;
    temp[temp.length-1]= lastLetter;

    String newTitleSearch= temp.toString();
    return newTitleSearch;
}

First, what is the cause of the output from this code?
Second, is there a better way to execute my solution?

  • 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-17T20:49:11+00:00Added an answer on May 17, 2026 at 8:49 pm

    You want:

    newTitleSearch = new String(temp);
    

    The toString method is not overridden for arrays; it’s the usual Object.toString, intended for debugging. The above actually creates a string of the characters. An alternative is:

    int len = titleSearch.length();
    String allButLast = titleSearch.substring(0, len - 1);
    newTitleSearch = allButLast + new Character(titleSearch.charAt(len - 1) + 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Here's a basic regex technique that I've never managed to remember. Let's say I'm
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm looking for suggestions for debugging... If you view this site in Firefox or
Basically, what I'm trying to create is a page of div tags, each has
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.