日期:2014-05-20 浏览次数:20905 次
public static void main(String[] arg) {
String srcStr = "我的心太乱要一些空白你若是明白让我暂时的离开!?";
String destString = "1234";
int lengh = srcStr.length();
Random random = null;
boolean isTrue = true;
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
while (isTrue) {
random = new Random();
int index = random.nextInt(lengh);
if (!map.containsKey(index)) {
map.put(index, index);
}
if (map.size() == 4) {
isTrue = false;
}
}
char[] srcArray = srcStr.toCharArray();
char[] destArray = destString.toCharArray();
int count = 0;
for (Integer key : map.keySet()) {
srcArray[key] = destArray[count];
count++;
}
System.out.println(String.valueOf(srcArray));
}
我1心太乱2一些空白你若是明4让我暂时的3开!?