I am trying to port some Android 2.x code to Android 1.5, here is the problematic line:
String[] myStringsArray = ...
...
myStringsArray.clear();
String[].clear() is not defined in Android 1.5, leading to this error:
[javac] MyClass.java:1692: cannot find symbol
[javac] symbol : method clear()
[javac] location: class java.lang.String[]
[javac] myStringsArray.clear();
What is the best I could use instead?
You can use the java.util.Arrays
utility class.
Arrays
provides a static method called fill()
which takes your Array
as the first parameter and the Object
or primitive to fill the array as the second parameter.
You could fill your Array with null
like this.
String myStringsArray[] = ...
Arrays.fill(myStringsArray, null);
Now every position in the Array is null.
没有为数组定义这种方法clear()
。您可以使用List<String>
并使用clear()
There is no such method to clear String[]
you can use new String[0]; to clear values from you string array
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.