Using password intoIt is debatable as to whether you should use String or use Char[] is always debatablefor this purpose because both the approaches hadhave their own utilityadvantages and disadvantage as welldisadvantages. It depending upondepends on what the need which user is expecting to be fulfilledneeds. Below lines may help better in understanding when to use which container : Since String
Since Strings in java isJava are immutable, whenever some tries to manipulate your string it creates a new Object and the existing String remains untemperedunaffected. This could be seen as an advantage for storing a password as a String, but on the other hand. String object remains in memory even after use. So somehow if anyone somehow got the memory location of the object, that person can easily trace your password stored at that location. While coming to
Char[] which is mutable, but it hadhas the advantage that after its usage, the programmer can expliciltyexplicitly clean the array or override values. So that after no usewhen it's done being used it is cleaned and no one could ever know about the information what you had stored.
Based on the above circumstances may be, one can get Ideaan idea whether to go with String or to go with Char[] for their requirement.
Thanksrequirements.