Here you can find the source of formatDifferentFileNames(List
public static List<String> formatDifferentFileNames(List<String> results)
//package com.java2s; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { private static final String IS_NOT_EXIST = "is not exist"; private static final int FIXED_LENGTH = 40; public static List<String> formatDifferentFileNames(List<String> results) { List<String> ret = new ArrayList<String>(); List<String> l1 = new ArrayList<String>(); List<String> l2 = new ArrayList<String>(); for (String str : results) { if (isContainNotExist(str)) { l1.add(str);/*from w ww .j a va 2s. com*/ } else { l2.add(str); } } Collections.sort(l1); Collections.sort(l2); ret.addAll(l2); if (l1.size() > 0 && l2.size() > 0) { ret.add(fillWithChar('=', 0, "")); ret.addAll(l1); } return ret; } public static boolean isContainNotExist(String str) { return str.indexOf(IS_NOT_EXIST) >= 0; } private static String fillWithChar(char c, int file_length, String baseSuffix) { StringBuilder sb = new StringBuilder(); int num = FIXED_LENGTH - file_length + baseSuffix.length(); System.out.println(" cur len = " + file_length + " fill num = " + num); for (int i = 0; i < num; i++) { sb.append(c); } return sb.toString(); } }