Android - 快速有效地清理字符数组
是否可以快速有效地清理 Java(Android)中的 char 数组?在治疗上进行另一个循环似乎对于优化解决方案来说太重了,不是吗?
这很奇怪,但如果不订阅付费网站,就不可能在互联网上找到这样的 Java 解决方案。
感谢您的关注
Is it possible to clean a char array in Java (Android) quickly and effectively? Make an other loop on the treatment seem to be to much heavy to be an optimised solution, doesn't it ?
It's strange but it is impossible to find such a solution in Java on the internet without having to subscribe to a pay site ..
Thank's to your attention
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用:
Arrays
类属于java.util
包。它使用泛型,因此您可以填充任何类型的数组。You can use:
Arrays
class belongs to thejava.util
package. It uses generics so you can fill any kind of array.为什么首先需要清除 char 数组?
大多数需要 char 数组在其中放入一些数据的函数(IO 读取等)都会返回放入的数据的长度,因此您可以忽略 char 数组中的其余数据。
Why do you need to clear a char array in the first place?
Most functions that want a char array to put some data in it (IO read, etc..) return the length of data that was put in, so you can disregard the rest of the data in char array.
使用布尔值来指示您的数组无效。
Use a boolean to indicate that your array is invalid.
我想知道是否预先确定由各种数据大小完成的数组的大小,或者让它的大小根据接收而变化是最好的方法?这是为了实现最快的处理。
谢谢
I would like to know whether predetermine the size of an array which will be completed by various data sizes, or let it size evolve according to the reception is the best way? This is intended to have the fastest processing.
Thank's
我认为这个问题的正确答案是通过执行以下操作将 char[] 的每个字符设置为空字符:
或者
执行
Arrays.fill(buffer, '0');
将填充所有 char[ ] 用字符“0”代替空字符。I think the correct answer to this question is to set each character of the char[] to null character by doing:
Or
Doing
Arrays.fill(buffer, '0');
will fill all the char[] with the character '0' instead of the null character.