【问题标题】:Replacing String array by another [duplicate]用另一个[重复]替换字符串数组
【发布时间】:2018-06-16 19:55:43
【问题描述】:

在开发 Android 项目时,我处于一个位置

就是这么简单

String[] subjects = {};
//It is a string array what I want transform by another
String[] another = {"Physics","Chemistry"};

如何用另一个主题替换主题

【问题讨论】:

    标签: java android arrays


    【解决方案1】:

    这样使用会有帮助

    String[] subjects = {};
    String[] another = {"Physics","Chemistry"};
    
    subjects  = another.clone();
    

    或第二个选项这样做

    subjects   = Arrays.copyOf(another , another .length);
    

    这会将您的另一个数组复制到您的主题数组

    【讨论】:

    • 不,它说这个变量不能被修改
    • 谢谢。我已将此变量设为最终变量
    • 是的,您需要删除最终关键字
    • 但是我做不到。
    • 你只需要在 answer 中编写相同的代码,如果你声明一个数组为 final 你不能改变它的值
    猜你喜欢
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 2013-07-11
    • 2013-12-03
    • 2019-12-03
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多