import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* 对字符串数组进行排序
* @author panjianghong
* @since 2016/8/31
* */
public class StringSort {
private static final Log _log = LogFactory.getLog(StringSort.class);
/**
* 对字符串数组进行排序
* @param keys
* @return
* */
public static String[] getUrlParam(String[] keys){
for (int i = 0; i < keys.length - 1; i++) {
for (int j = 0; j < keys.length - i -1; j++) {
String pre = keys[j];
String next = keys[j + 1];
if(isMoreThan(pre, next)){
String temp = pre;
keys[j] = next;
keys[j+1] = temp;
}
}
}
return keys;
}
/**
* 比较两个字符串的大小,按字母的ASCII码比较
* @param pre
* @param next
* @return
* */
private static boolean isMoreThan(String pre, String next){
if(null == pre || null == next || "".equals(pre) || "".equals(next)){
_log.error("字符串比较数据不能为空!");
return false;
}
char[] c_pre = pre.toCharArray();
char[] c_next = next.toCharArray();
int minSize = Math.min(c_pre.length, c_next.length);
for (int i = 0; i < minSize; i++) {
if((int)c_pre[i] > (int)c_next[i]){
return true;
}else if((int)c_pre[i] < (int)c_next[i]){
return false;
}
}
if(c_pre.length > c_next.length){
return true;
}
return false;
}
public static void main(String[] args) {
String[] keys = getUrlParam(new String[]{"fin","abc","shidema","shide","bushi"});
for (String key : keys) {
System.out.println(key);
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有