For this reason the Java JPasswordField getPassword() method returns an array with no other copies around. An array can also easily be zero'd out with fill().
http://docs.oracle.com/javase/tutorial/uiswing/components/pa...
http://docs.oracle.com/javase/tutorial/uiswing/components/pa...
This will leave the "hello" in ram (subject to GC):
String x = "hello"
x = null;
This will clear the "hello" from ram: char[] x = new char[]{'h','e','l','l','o'};
x[0] = '0'; x[1] = '0'; ...
This will leave the "hello" in ram (subject to GC): char[] x = new char[]{'h','e','l','l','o'};
x = null;