If you want every element to become an empty string then iterate over the array and assign each element to be an empty string
If you want to take an array that has say 3 elements and make it so that it has no elements then you should not be using an array. You want to use an ArrayList which can have its size changed
If you had String[] str = {"hi","hello","hey"};
and did str = new String[0];
str would then be {} ?
Try it with this
String[] str = { "hi", "hello", "hey" };
println("#");
for (String s : str)
println(s);
str = new String[0];
println("#");
for (String s : str)
println(s);
println("#");
// Now the array has no elements so attempting to use
// the array would cause an index out of range exception
Answers
You can't "clear" an array but maybe you're looking for something like this?
or
so if I had an array like
String[] str = {"hi","hello","hey"};
and then did
str = null;
str would then be {} ?
@colouredmirrorball
0
or an""
empty String for example:https://docs.Oracle.com/javase/8/docs/api/java/util/Arrays.html#fill-java.lang.Object:A-java.lang.Object-
If you want every element to become an empty string then iterate over the array and assign each element to be an empty string
If you want to take an array that has say 3 elements and make it so that it has no elements then you should not be using an array. You want to use an ArrayList which can have its size changed
For a more specialized dynamically-sizable String container, what about StringList: :D
https://Processing.org/reference/StringList.html
If you had
String[] str = {"hi","hello","hey"};
and did
str = new String[0];
str would then be {} ?
Try it with this
Output is
thanks everyone! that helped a lot. :)
I have asked many questions about a program I have been doing (this being one of them) and I hope to be able to show you a PREVIEW of it soon! :D
forum.processing.org/two/discussion/12211/whitablet-one-preview