Java Array Sort sortSubFiles(String[] p_subFiles)

Here you can find the source of sortSubFiles(String[] p_subFiles)

Description

Sort the separated file by the suffix number in the filename

License

Apache License

Parameter

Parameter Description
p_subFiles Separated files without order

Return

String[] Sorted separated file array

Declaration

private static String[] sortSubFiles(String[] p_subFiles) 

Method Source Code

//package com.java2s;
/**//from  ww  w  .  ja v a2s.  com
 * Copyright 2009 Welocalize, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */

public class Main {
    /**
     * Sort the separated file by the suffix number in the filename
     * 
     * @param p_subFiles
     *            Separated files without order
     * @return String[] Sorted separated file array
     * 
     * @version 1.0
     * @since 8.2.2
     */
    private static String[] sortSubFiles(String[] p_subFiles) {
        if (p_subFiles == null || p_subFiles.length == 0)
            return p_subFiles;

        int length = p_subFiles.length;
        String[] sortedSubFiles = new String[length];
        String tmp = "";
        int index = -1;
        for (int i = 0; i < length; i++) {
            tmp = p_subFiles[i];
            tmp = tmp.substring(0, tmp.lastIndexOf("."));
            tmp = tmp.substring(tmp.lastIndexOf("_") + 1);
            index = Integer.parseInt(tmp) - 1;
            sortedSubFiles[index] = p_subFiles[i];
        }
        return sortedSubFiles;
    }
}

Related

  1. sortStringArrayAlphabetically(String[] strings)
  2. sortStrings(final String[] strings)
  3. sortStrings(String[] strings)
  4. sortStrings(String[] strings)
  5. sortStrings(String[] strings)
  6. sortTable(String[][] data, int index)
  7. sortToFXYSumOrder(final double[] coeffs)
  8. sortTwoArrays(A[] firstArray, B[] secondArray)
  9. sortWith(final int[] ary, int[] ary2)