Java 实例 - 字符串替换

Java 教程 · 2019-02-10 07:13:07

如何使用java替换字符串中的字符呢?

以下实例中我们使用 java String 类的 replace 方法来替换字符串中的字符:

StringReplaceEmp.java 文件

public class StringReplaceEmp{ public static void main(String args[]){ String str="Hello World"; System.out.println( str.replace( 'H','W' ) ); System.out.println( str.replaceFirst("He", "Wa") ); System.out.println( str.replaceAll("He", "Ha") ); } }

以上代码实例输出结果为:

Wello World
Wallo World
Hallo World

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and

AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and

George F. Luger、William A Stubblefield / Addison Wesley / 2008-09-04 / USD 22.20

This book is designed for three primary purposes. The first is as a programming language component of a general class in Artificial Intelligence. From this viewpoint, the authors see as essential that......一起来看看 《AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and 》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

html转js在线工具
html转js在线工具

html转js在线工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具