1、1!apublic class SubStringDemo public static void main(String args) / String str = hanbasdnbafllgnbahjnbakqqqqlnbaxnbai;String regex = nba;/ 1int count = getCount1(str, regex);/ 2int count2 = getCount2(str, regex);System.out.println(count);System.out.println(count2);/* * 2 */private static int getCou
2、nt2(String str, String regex) / int count = 0;/ int index = 0;/ while (index = str.indexOf(regex, index) != -1) / +index = index + regex.length();/ +count+;return count;/* * 1 * int * * */public static int getCount1(String maxString, String minString) / int count = 0;/ int index
3、= 0;/ -1while (index = maxString.indexOf(minString) != -1) / +count+;/ ,maxString = maxString.substring(index + minString.length();return count;babbbbbccccdddeea(1)b(5)c(4)d(3)e(2)public class Test5 public static void main(String args) throws IOException / 1,String s = abbbbbccccdddee;/ 2,char arr =
4、 s.toCharArray();/ 3,洢TreeMap map = new TreeMap();/ 4,洢for (char c : arr) / 5,洢,1洢,1洢if (!map.containsKey(c) / map.put(c, 1); else map.put(c, map.get(c) + 1);/ 6,StringBuilder sb = new StringBuilder();for (Character key : map.keySet() / hm.keySet()sb.append(key + ( + map.get(key) + );/ System.out.pr
5、intln(sb);/ BufferedWriter bw = new BufferedWriter(new FileWriter(result.txt);bw.write(sb.toString();bw.close();3.javapublic class Test6 public static void main(String args) throws IOException File src = new File(D:src); / File dest = new File(D:dest); / if (src.equals(dest) System.out.println(); el
6、se copy(src, dest);/* * () 1,void 2,File src,File dest */public static void copy(File src, File dest) throws IOException / 1,洢FileFile subFiles = src.listFiles();/ 2,for (File subFile : subFiles) / 3,.javaioif (subFile.isFile() / .javaif (subFile.getName().endsWith(.java) BufferedInputStream bis = n
7、ew BufferedInputStream(new FileInputStream(subFile);/ File fff = new File(dest, subFile.getName(); / / + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fff);int b;while (b = bis.read() != -1) bos.write(b);bis.close();bos.close();/ 4, else copy(subFile, dest);2:(1)2()(2)354a:5b:532c:3d:523e:5f:5354(3)8()2()a:3.棬b:3档32