When I read java source code, I found in the collection interface, will be safe
The returned array will be "safe" in that no references to it are Maintained by this collection.(In other words, this method must allocate a new array even if this collection is backed by an array).The caller is thus free to modify the returned array.
I do not understand the meaning, can you provide an example for me?
Sure:
List<String> list = Arrays.asList("foo", "bar", "baz");
String[] array = list.toArray(new String[0]);
array[0] = "qux";
System.out.println(list.get(0)); // still "foo"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With