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 3 of 3

Thread: The += assignment operator?

  1. #1
    Member
    Join Date
    Aug 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default The += assignment operator?

    Hey guys I have a quick question. Could anyone explain to me what the += does and how it works? I have seen it in different examples that use arrays but I still don't get what it's supposed to do.

    Here is an example I saw in my book:

    a[5] = 10;
    i = 5;
    a[i++] += 2;


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: The += assignment operator?

    These two are functionally equivalent:

    a += expr

    a = a + (expr)

    Same goes for all the other blah-equals operators (-=, *=, ...etc).

  3. The Following 2 Users Say Thank You to helloworld922 For This Useful Post:

    jean28 (January 19th, 2013), lanmonster (January 27th, 2013)

  4. #3
    Member
    Join Date
    Aug 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: The += assignment operator?

    Thank you very much!

Similar Threads

  1. meaning of operator ( |= )
    By ashish12169 in forum Java Theory & Questions
    Replies: 1
    Last Post: July 18th, 2012, 02:05 AM
  2. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  3. Remainder Assignment Operator Help
    By jsam0123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 5th, 2011, 06:04 PM
  4. Error with OR operator
    By tarkal in forum Loops & Control Statements
    Replies: 3
    Last Post: September 4th, 2011, 02:49 PM
  5. Operator Problem
    By KevinGreen in forum Algorithms & Recursion
    Replies: 2
    Last Post: November 2nd, 2009, 09:50 AM