reset password
Author Message
Arnav98
Posts: 48
Posted 18:58 Mar 09, 2017 |

Since strings in java are immutable i.e there value cannot be changed, are we supposed to validate user input using a loop ? Because if you try doing that the next input cannot be stored in the same string.

kknaur
Posts: 540
Posted 19:21 Mar 09, 2017 |

Be sure you understand what it means to be immutable.  This means that you can't change the value of the original string in memory.  You can still assign a new string to the same variable, but any changes to a string create a new string in memory and assign the reference to point to the new string and the old one becomes garbage.