package com.webkfa.test; /** * web开发技术提供 * 网址: * http://www.webkfa.com */ public class Test { public static void main(String[] args) { //java解决split字符|的问题 String str="1|2|3|4|"; String arr[]=str.split("|"); System.out.println("arr.length长度为9:"+arr.length); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } //解决办法,|是转义字符 String str1="1|2|3|4|"; String arr1[]=str1.split("\\|"); System.out.println("arr.length长度为4:"+arr1.length); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }