码迷,mamicode.com
首页 > 编程语言 > 详细

Java 实例 – List 元素替换 - Break易站

时间:2020-07-13 21:46:49      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:array   int   tran   asList   break   static   string   使用   void   

[

Java 实例 - List 元素替换

Java 实例
以下实例演示了如何使用 Collections 类的 replaceAll() 来替换List中所有的指定元素:

Main.java 文件

import java.util.*;
 
public class Main {
public static void main(String[] args) {
List list = Arrays.asList("one Two three Four five six one three Four".split(" "));
      System.out.println("List :"+list);
      Collections.replaceAll(list, "one", "hundrea");
      System.out.println("replaceAll: " + list);
   }
}

以上代码运行输出结果为:


List :[one, Two, three, Four, five, six, one, three, Four]

replaceAll: [hundrea, Two, three, Four, five, six, hundrea, three, Four]

Java 实例

]
转载请保留页面地址:https://www.breakyizhan.com/java/23791.html

Java 实例 – List 元素替换 - Break易站

标签:array   int   tran   asList   break   static   string   使用   void   

原文地址:https://www.cnblogs.com/breakyizhan/p/13295636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!