Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: concatenation of a string

  1. #1
    Junior Member
    Join Date
    Nov 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default concatenation of a string

    a string created with String class is immutable but when we use the += operator
     String ch="hello"; ch+= "world";
    what happens in the memory it creates a new string? or change reference?
    another question why we don't use:
     for (int i=0;i<ch.length();i++) {System.out.println(ch[i]); }
    thank you
    Last edited by toubi; November 19th, 2022 at 12:10 PM.

  2. #2
    Member
    Join Date
    Jun 2022
    Posts
    41
    Thanks
    1
    Thanked 3 Times in 2 Posts

    Default Re: manipulation of a string

    final String myImmutableString = "hello";
    String ordinaryString = " world";
     
    myImmutableString += ordinaryString;
    Quote Originally Posted by IDE
    The final local variable myImmutableString cannot be assigned. It must be blank and not using a compound assignment. Java(536870970)

Similar Threads

  1. [SOLVED] String Manipulation.
    By Praetorian in forum Java Theory & Questions
    Replies: 6
    Last Post: February 19th, 2014, 11:52 AM
  2. string manipulation
    By nhiap6 in forum Java Theory & Questions
    Replies: 2
    Last Post: November 17th, 2012, 06:32 AM
  3. string manipulation
    By nhiap6 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 16th, 2012, 12:28 PM
  4. String Manipulation.
    By Nemus in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 21st, 2011, 03:02 PM
  5. String manipulation help
    By Duff in forum Loops & Control Statements
    Replies: 7
    Last Post: March 19th, 2010, 04:02 AM

Tags for this Thread