0

For example:

String result;

String letter_a = "a";

String letter_b = "b";

String letter_c = "c";

We know it's easy to concatenate strings like result = letter_a + letter_b + letter_c .

Currently, the value of the result is "abc".

But what if I want to subtract letter_c to result like result = result - letter_c. Will the result be result = "ab"?

Michael
  • 41,989
  • 11
  • 82
  • 128

2 Answers2

0

Use replace on the string so it will be final.replace("c",""); reassign this to final or any other variable

  • I don't know whether replacing with nothing is really the same thing as string subtraction. – Michael Jun 29 '17 at 11:18
  • Well ull replace it with nothing means tht place will become place suppose ur string is abc or acb or cba or cab so applying replace on c with nthn will make u left with a and b :) – Wali Muhammad Khubaib Jun 29 '17 at 15:20
0

No, it will give you a compilation error as error: bad operand types for binary operator '-'

Go for substring() and store it back in final1 variable again. For your case, final1 =final1.substring(0,final1.length()-1);

Aakash Verma
  • 3,705
  • 5
  • 29
  • 66