public static void main(String[] args) {
		 String s = "GET             /index.html HTTP/1.1";//字符串s由“GET”、“/index.html”和“HTTP/1.1”组成,中间有一个或多个空格
		  String tt[] = s.split("\\s{1,}");//按照空格分割字符串,多个空格作为一个空格对字符串进行分割
		  for(String str: tt){//增强的for循环
		  System.out.println(str);//输出:GET
		  }
		                                     //  /index.html
		                                    //  HTTP/1.1          
		  String qq = s.replaceAll(" {2,}", " ");//把字符串s中的多个空格替换为一个空格
		  System.out.println(qq);//输出:GET /index.html HTTP/1.1 
		  System.out.println(s);//输出:GET             /index.html HTTP/1.1
	}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-09-07
猜你喜欢
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
相关资源
相似解决方案