作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个方法
public boolean findANDsetText (String Description, String ... extra ) {
在里面我想调用另一个方法并将它传递给 extras
但我想向 extras 添加新元素 (Description)。
object_for_text = getObject(find_arguments,extra);
我如何在 Java 中做到这一点?代码会是什么样子?
我厌倦了容纳来自 this question 的代码但无法让它发挥作用。
最佳答案
为了扩展这里的一些其他答案,数组复制可以用更快地完成
String[] newArr = new String[extra.length + 1];
System.arraycopy(extra, 0, newArr, 0, extra.length);
newArr[extra.length] = Description;
关于java - 如何向 Varargs 添加新元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11321784/
我是一名优秀的程序员,十分优秀!