日期:2014-05-20 浏览次数:20666 次
import java.util.*; public class Insert{ public static void insert(String str, int a, int b){ String[] strArray = str.split("-"); int[] intArray = new int[strArray.length+2]; for(int i=0; i<strArray.length; i++) intArray[i] = Integer.valueOf(strArray[i]); intArray[intArray.length-2] = a; intArray[intArray.length-1] = b; Arrays.sort(intArray); TreeSet<Integer> set = new TreeSet<Integer>(); String output = ""; for(int j=0; j<intArray.length; j++) set.add(intArray[j]); Iterator iterator = set.iterator(); while(iterator.hasNext()) output += iterator.next() +"-"; System.out.println(output.substring(0, output.length()-1)); } public static void main(String args[]){ String str = "1-2-3-4-6-11-13-16"; int a = 4; int b = 17; insert(str, a, b); } }