Java 实例 - List 元素替换

Java 教程 · 2019-02-11 19:26:49

以下实例演示了如何使用 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://codercto.com/courses/l/12.html

查看所有标签

Web Design Handbook

Web Design Handbook

Baeck, Philippe de 编 / 2009-12 / $ 22.54

This non-technical book brings together contemporary web design's latest and most original creative examples in the areas of services, media, blogs, contacts, links and jobs. It also traces the latest......一起来看看 《Web Design Handbook》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具