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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:48:55+00:00 2026-06-18T07:48:55+00:00

I have two textareas. When I type something in the first textarea, it shows

  • 0

I have two textareas. When I type something in the first textarea, it shows up in the second one with documentlistener. I want to use replace to replace certain words with different words (like a translator).

My DocumentListener looks like this:

DocumentListener documentListener = new DocumentListener() {

    public void changedUpdate(DocumentEvent documentEvent) {
        printIt(documentEvent);
    }
    public void insertUpdate(DocumentEvent documentEvent) {
        printIt(documentEvent);
    }
    public void removeUpdate(DocumentEvent documentEvent) {
        printIt(documentEvent);
    }
    private void printIt(DocumentEvent documentEvent) {
        DocumentEvent.EventType type = documentEvent.getType();
        String typeString = null;
        if (type.equals(DocumentEvent.EventType.CHANGE)) {
        }  
        else if (type.equals(DocumentEvent.EventType.INSERT)) {
            String hello = area1.getText();
        hello.replace("hei", "hello");
        area2.setText(hello);
        }
        else if (type.equals(DocumentEvent.EventType.REMOVE)) {
            String hello = area1.getText();
        area2.setText(hello);
        }
    }
};

This doesn’t work though. I thought the hello.replace would replace the word hei typed in area1 with hello, which would be displayed in area2. However, it doesnt change the word. So what am I doing wrong?

Thanks!

  • 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-18T07:48:56+00:00Added an answer on June 18, 2026 at 7:48 am

    Strings are immutable; they can’t be changed. And so:

    hello.replace("hei", "hello");
    

    Should be:

    hello = hello.replace("hei", "hello");
    

    Replace method has to return you a NEW string with your changes in it because it can’t modify the original.

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

Sidebar

Related Questions

Well, I have two textareas. When a user will type in one textarea, it
I have two input textareas, and the second one is hidden. Is it possible
I have an input form with two textareas allowing a user to type in
I have those two html radio buttons and textarea. I basically want to enable
I have two functions: one that creates a new <textarea> when a button is
I have two textures that are both .jpg, which represent a sky (one during
I have two textures generated using a fragment shader. I want to be able
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two classes (MVC view model) which inherits from one abstract base class.
So I have a normal form with 1 textarea and two hidden inputs, which

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.