This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Strings  RSS feed

 
Arun Pai
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are legal operations on s?
String s = "something";
A.s >>= "ok";
B.char c = s[4];
C.s += 3;
D.s -= "thing";
E.s = s + "good";

Answer is C & E ??
-Arun
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it's possible to concatenate strings with the + operator. But it isn't possible to substract, shift or access them as they would be a char array.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jose Botella:
Because it's possible to concatenate strings with the + operator. But it isn't possible to substract, shift or access them as they would be a char array.

Exactly -- in Java the + operator is overloaded -- meaning it has a different function depending on the type of operands it is used with.
So C would produce the string "Something3"
and E would produce the string "Somethinggood"
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!