java中判斷兩個字符串是否相等,並獲取不同的元素

這裏只貼出主要運行的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);

 }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章