Java Split()方法按点(.)切分注意细节

按点(.)切分,必须要注意转义!如:split("\.")。

例子:

  1. public class Test {  
  2.   
  3.     public static void main(String[] args) {  
  4.         String s = "adhahd.txt";  
  5.         String t[] = s.split("\.");  
  6.         for(int i = 0; i < t.length; i++){  
  7.             System.out.println(t[i]);  
  8.         }  
  9.     }  
  10. }  
public class Test {

	public static void main(String[] args) {
		String s = "adhahd.txt";
		String t[] = s.split("\.");
		for(int i = 0; i < t.length; i++){
			System.out.println(t[i]);
		}
	}
}

输出结果:
  1. adhahd  
  2. txt  




原文地址:https://www.cnblogs.com/Jeremy2001/p/6885367.html