java_去除字符串中的空格的几种方法
来源:互联网 发布:阿里云搭建ss教程 编辑:程序博客网 时间:2024/06/03 21:59
/** * */package 作业0919;import java.util.regex.Matcher;import java.util.regex.Pattern;public class 去除空格 {public static void main(String[] args) {String string = "aa bb cc dd";String string1 = "";// 方法一:String string2 = string.replaceAll(" ", "");System.out.println(string2);// 方法二:for (int i = 0; i < string.length(); i++) {if (!String.valueOf(string.charAt(i)).equals(" ")) {string1 += string.charAt(i);}}System.out.println(string1);// 方法三:String regex = "\\s";String[] string3 = string.split(regex);String string4 = "";for (int i = 0; i < string3.length; i++) {string4 += string3[i];}System.out.println(string4);System.out.println("************");Matcher matcher = Pattern.compile(regex).matcher(string);while (matcher.find()) {System.out.println(matcher.group());}}}
阅读全文
0 0
- java_去除字符串中的空格的几种方法
- C#去除字符串空格的几种方法
- Java:去除字符串中空格的几种方法
- C#去除字符串空格的几种方法1.
- Java中去除字符串中空格的几种方法
- Java:去除字符串中空格的几种方法
- Java中去除字符串中空格的几种方法
- Java中去除字符串中所有空格的几种方法
- Java中去除字符串中所有空格的几种方法
- Java中去除字符串中所有空格的几种方法
- Java中去除字符串中所有空格的几种方法
- java 中去除字符串中的空格,两种方法
- JavaScript去除空格的几种方法 (trim)
- JavaScript去除空格的几种方法 (trim)
- JavaScript去除空格的几种方法 (trim)
- 去除字符串中的空格
- 去除字符串中的空格
- 去除字符串中的空格
- MySQL 配置记录
- 代码获取颜色的方法
- Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor
- 机器学习sklearn参数解释(GDBT+XGBOOST)
- 第二次 第一个小项目(基于链表的增删改查)(仓库货物管理系统)
- java_去除字符串中的空格的几种方法
- Hibernate——对象的三大状态
- python语言入门
- merge_intervals
- C#反射(Reflection)详解
- qtablewidget item不可以修改
- 九度题目1074:对称平方数
- jQuery和jQuery UI的区别
- 表示学习1-word2vec