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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:10:32+00:00 2026-06-10T09:10:32+00:00

Someone on stackoverflow gave this code that finds the position of chars… Now the

  • 0

Someone on stackoverflow gave this code that finds the position of chars… Now the problem is, its a loop that searches the whole string and returns each position… Now in this code an example “pool” is used. So it returns 1 and 2

String s = "Pool";
int idx = s.indexOf('o');
while (idx > -1) {
System.out.println(idx);
idx = s.indexOf('o', idx + 1);
}

Is there a way to use both positions returned in a method and replace the chars… For instance if I wanted to replace the ‘o’ with ‘hh’ resulting in ‘phhl’

  • 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-06-10T09:10:34+00:00Added an answer on June 10, 2026 at 9:10 am

    I would recommend the solution by @Sujay, but just in case that does not meet your requirement…

    int counter = 0;
    String input = "Pool";
    char replacement = 'l';
    char[] inputArray = input.toCharArray();
    for(char ch : inputArray) {
        if(ch == 'o') {
            inputArray[counter] = replacement;
        }
        counter += 1;
    }
    String output = new String(inputArray);
    System.out.println(output);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Someone in Stack Overflow gave me this code: $output = preg_replace( '/(\+?\d{2}|0)(\d{7,8})/', '0$2', $test);
On some StackOverflow question about GWT cons and pros from 2009 someone answered that:
This StackOverflow answer has an image of KDiff3 highlighting intra-line differences. Does someone know
Someone told me in an answer to a stackoverflow question that the two big
Can someone point me where am I doing it wrong. This is my code:
Someone from stackoverflow recently helped me form this sql query to return the data
A week or so ago someone on StackOverflow asked why their Python code for
Someone from stackoverflow helped me with my code for buttons by giving me the
This is my first question on stackoverflow, hopefully there is someone who can help
Someone explain why the next code returns a pointer inside ntdll.dll? GetProcAddress(LoadLibraryA(kernel32.dll), EncodePointer); GetProcAddress(LoadLibraryA(kernel32.dll),

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.