如何在java中删除和更新字符串数组

时间:2018-01-11 15:27:44

标签: java arrays

代码:

String[] myStringArray = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

String input = "Monday"

输出:

String[] newInput = {"Tuesday","Wednesday","Thursday","Friday","Saturday"};

那么如何在java中删除要在数组中更新的特定输入?

2 个答案:

答案 0 :(得分:1)

试试这个:

public static void main(final String[] args) {
    String[] myStringArray = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
    String input = "Monday";
    String[] output = Arrays.stream(myStringArray).filter(e -> !e.equals(input)).toArray(String[]::new);
    System.out.println(Arrays.toString(output));
}

答案 1 :(得分:0)

<!-- Example div -->
<div id="test"></div>

真正可怕的代码片段,但我希望它有所帮助 - 我尽可能保持简单。