在使用前记得加载jar包()pinyin4i.jar
import net.sourceforge.pinyin4j.PinyinHelper;
}
import java.util.Comparator;
public class PinyinComparator implements Comparator
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Test
{
@SuppressWarnings("unchecked")
public void sort()
{
List
List
String[] array = { "陈少华", "熊易", "周武", "去情分", "aa", "dddd", "gggg",
"zzzz" };
for (int i = 0; i < array.length; i++)
{
java j = new java();
j.setName(array[i]);
j.setAge(10001 + i);
list.add(j);
}
@SuppressWarnings("rawtypes")
List list1 = Arrays.asList(array);
Arrays.sort(array, new PinyinComparator());
System.out.println(list1.size());
System.out.println(list.size());
for (int i = 0; i < list1.size(); i++)
{
for (int x = 0; x < list.size(); x++)
{
if (list1.get(i).toString().equals(list.get(x).getName()))
{
java ja = new java();
ja.setName(list1.get(i).toString());
ja.setAge(list.get(x).getAge());
templist.add(ja);
}
}
}
System.out.println(list1);
for (int i = 0; i < templist.size(); i++)
{
System.out.println(templist.get(i).getName() + " "
+ templist.get(i).getAge());
}
}
public static void main(String[] args)
{
new Test().sort();
}
class java
{
private int age;
private String name;
/**
* @return the age
*/
public int getAge()
{
return age;
}
/**
* @param age
* the age to set
*/
public void setAge(int age)
{
this.age = age;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name)
{
this.name = name;
}
}
}