Java 在J2ME平台上对字符串对象数组进行排序
对字符串数组进行排序的最佳(最快)方法是什么(使用Java 1.3)。您可以使用此代码对字符串值进行排序Java 在J2ME平台上对字符串对象数组进行排序,java,string,sorting,java-me,Java,String,Sorting,Java Me,对字符串数组进行排序的最佳(最快)方法是什么(使用Java 1.3)。您可以使用此代码对字符串值进行排序 public Vector sort(String[] e) { Vector v = new Vector(); for(int count = 0; count < e.length; count++) { String s = e[count]; int i = 0; for
public Vector sort(String[] e) {
Vector v = new Vector();
for(int count = 0; count < e.length; count++) {
String s = e[count];
int i = 0;
for (i = 0; i < v.size(); i++) {
int c = s.compareTo((String) v.elementAt(i));
if (c < 0) {
v.insertElementAt(s, i);
break;
} else if (c == 0) {
break;
}
}
if (i >= v.size()) {
v.addElement(s);
}
}
return v;
}
公共向量排序(字符串[]e){
向量v=新向量();
对于(int count=0;count=v.size()){
v、 增编;
}
}
返回v;
}
另请参见此使用气泡排序的示例代码
static void bubbleSort(String[] p_array) throws Exception {
boolean anyCellSorted;
int length = p_array.length;
String tmp;
for (int i = length; --i >= 0;) {
anyCellSorted = false;
for (int j = 0; j < i; j++) {
if (p_array[j].compareTo(p_array[j + 1]) > 0) {
tmp = p_array[j];
p_array[j] = p_array[j + 1];
p_array[j + 1] = tmp;
anyCellSorted = true;
}
}
if (anyCellSorted == false) {
return;
}
}
}
静态void bubbleSort(字符串[]p_数组)引发异常{
布尔任意单元排序;
int length=p_array.length;
串tmp;
对于(int i=length;--i>=0;){
anycellsorded=false;
对于(int j=0;j0比较{
tmp=p_阵列[j];
p_数组[j]=p_数组[j+1];
p_阵列[j+1]=tmp;
anyCellSorted=true;
}
}
if(anyCellSorted==false){
回来
}
}
}
您可以使用此代码对字符串值进行排序
public Vector sort(String[] e) {
Vector v = new Vector();
for(int count = 0; count < e.length; count++) {
String s = e[count];
int i = 0;
for (i = 0; i < v.size(); i++) {
int c = s.compareTo((String) v.elementAt(i));
if (c < 0) {
v.insertElementAt(s, i);
break;
} else if (c == 0) {
break;
}
}
if (i >= v.size()) {
v.addElement(s);
}
}
return v;
}
公共向量排序(字符串[]e){
向量v=新向量();
对于(int count=0;count=v.size()){
v、 增编;
}
}
返回v;
}
另请参见此使用气泡排序的示例代码
static void bubbleSort(String[] p_array) throws Exception {
boolean anyCellSorted;
int length = p_array.length;
String tmp;
for (int i = length; --i >= 0;) {
anyCellSorted = false;
for (int j = 0; j < i; j++) {
if (p_array[j].compareTo(p_array[j + 1]) > 0) {
tmp = p_array[j];
p_array[j] = p_array[j + 1];
p_array[j + 1] = tmp;
anyCellSorted = true;
}
}
if (anyCellSorted == false) {
return;
}
}
}
静态void bubbleSort(字符串[]p_数组)引发异常{
布尔任意单元排序;
int length=p_array.length;
串tmp;
对于(int i=length;--i>=0;){
anycellsorded=false;
对于(int j=0;j0比较{
tmp=p_阵列[j];
p_数组[j]=p_数组[j+1];
p_阵列[j+1]=tmp;
anyCellSorted=true;
}
}
if(anyCellSorted==false){
回来
}
}
}
使用
如果由于平台的限制,由于某种原因无法实现,您可以从其来源获得想法。使用
如果由于平台的限制,由于某种原因无法实现,您可以从其来源获得想法。第一个函数(插入排序)实际上不是排序:如果(c==0)中断,它会删除重复项第一个函数(插入排序)实际上不是一个排序:如果(c==0)中断,它会由于而删除重复项代码>子句。