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  



 


posted @ 2017-05-21 17:18  jeremy1888  阅读(1652)  评论(0编辑  收藏  举报