Package com.rick.sample; Import Java.util.arraylist;import java.util.collections;import java.util.comparator;import java.util.List; public class Sortutildemo {Public static void Sortidentify (List<string> lists) {sortcomparator sortcomparator = new Sortcomparator ();collections.sort (lists, sortcomparator); }Public static void Main (string[] args) {arraylist<string> lists = new arraylist<string> ();Lists.add ("1.1");Lists.add ("1.2");Lists.add ("1.2.1");Lists.add ("3.1.2");Lists.add ("2.6.6");Lists.add ("2.6.3");Lists.add ("1.10.1");Lists.add ("1.10.2");Lists.add ("1.10.1.2");Lists.add ("1.1.1");Lists.add ("10.1.1");sortidentify (lists);For (String ids:lists) {System.out.println (IDS); } }}/** * Override sort interface * @author Administrator */class Sortcomparator implements comparator<string>{@Overridepublic int Compare (string pre, String suf) {string[] Prearrs = pre.split ("\ \");string[] Sufarrs = suf.split ("\ \");int len = prearrs.length > sufarrs.length? preArrs.length:sufArrs.length;for (int i = 0; i < len; i++) {int prenum = 0;int sufnum = 0;if (i < prearrs.length) {prenum = Integer.parseint (Prearrs[i]); }if (i <sufarrs.length) {sufnum = Integer.parseint (Sufarrs[i]); }if (Prenum > Sufnum) {return 1;} else if (Prenum < sufnum) {return-1; } }return 0; }}
160308, Java sort (shape like 1.1, 1.2.1)