File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strings

 
Arun Pai
Ranch Hand
Posts: 143
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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