subList方法用于获取列表中指定范围的子列表,该列表支持原列表所支持的所有可选操作.返回列表中指定范围的子列表. 语法 subList(int fromIndex, int toIndex) fromIndex:用于指定新列表的起始点(包括该点). toIndex:用于指定新列表的结束点(不包括该点). 用法实例: public static void main(String[] args) { List<String> list = new
截取指定长度的字符串,如果超出就用more的内容来替换 截取的字节数,截取的时候,有可能会少截取一位(当最后一位是1个双字节的话,会少截取一个) public class Test { public static void main(String[] args) { String s="a测试bcd试1"; System.err.println(subAndReplaceString(s, 50, "...")); }
编程:编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串. 但是要保证汉字不被截半个,如"我ABC"4 public class StringSplit { public static void main(String[] args) throws Exception { String ss = "a很bc你好"; System.out.println(splitString(ss, 1)); } public static String