這裏只貼出主要運行的main方法, 大家自行創建包,類
public
static
void
main(String[] args) {
String text1 = "ge1,ge2,ge3,ge4,ge5";
String text2 = "ge1,ge4,ge3,ge5";
StringBuilder sb = new StringBuilder();
String[] strings = text1.split(",");
for (String s : strings) {
if (!text2.contains(s)) {
sb.append(s + ",");
}
}
String c = sb.substring(0, sb.length()).toString();
System.out.println("text1文本中text2沒有的元素是:"+c);
}