• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strings

 
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"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic