第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

比較 2 個(gè)文本文件并找出列表中的差異并找出哪些列表值不匹配

比較 2 個(gè)文本文件并找出列表中的差異并找出哪些列表值不匹配

白衣染霜花 2023-05-24 16:11:58
我正在使用 Scanner 讀取 2 個(gè)文本文件(可能包含重復(fù)項(xiàng))并將它們寫入 arraylist。我正在比較兩個(gè) arraylist 以找出差異。當(dāng)我打印出來時(shí),我可以看到有什么區(qū)別,但我不知道哪個(gè)記錄來自哪個(gè)文件(文本文件名)text1.txt 中的內(nèi)容TIMESTAMP,FE,TDI,20190703113119,20190601000000,20190701000000,TIMESTAMP,FE,KYMI,20190703113130,20190601000000,20190701000000,TIMESTAMP,FE,UMRI,20190703113154,20190601000000,20190701000000,TIMESTAMP,FE,MLI,20190703113211,20190601000000,20190701000000,TIMESTAMP,FE,WOLI,20190703113221,20190601000000,20190701000000,TIMESTAMP,FE,VEM,20190703113221,20190601000000,20190701000000,TIMESTAMP,FE,ZER,20190703113154,20190601000000,20190701000000,text2.txt 中的內(nèi)容TIMESTAMP,FE,TDL,20190703113119,20190601000000,20190701000000,TIMESTAMP,FE,KYMA,20190703113130,20190601000000,20190701000000,TIMESTAMP,FE,UMRC,20190703113154,20190601000000,20190701000000,TIMESTAMP,FE,MLW,20190703113211,20190601000000,20190701000000,TIMESTAMP,FE,WOLF,20190703113221,20190601000000,20190701000000,TIMESTAMP,FE,VEM,20190703113221,20190601000000,20190701000000,TIMESTAMP,FE,ZER,20190703113154,20190601000000,20190701000000,代碼:Scanner prodScanner = new Scanner(prodFile);     while (prodScanner.hasNextLine()) {     String currentRecord = prodScanner.nextLine().trim();                     if (currentRecord.length() > 0) {                    prodRecordsFromStatement.add(currentRecord);                  }           }Scanner nonProdScanner = new Scanner(nonProdFile);while (nonProdScanner.hasNextLine()) {            String currentRecord = nonProdScanner.nextLine().trim();              if (currentRecord.length() > 0) {                                        nonProdRecordsFromStatement.add(currentRecord);                                }                            }Collection<String> result = new ArrayList<>(CollectionUtils.disjunction(prodRecordsFromStatement, nonProdRecordsFromStatement)); List<String> resultList = new ArrayList<>(result); Collections.sort(resultList);
查看完整描述

2 回答

?
婷婷同學(xué)_

TA貢獻(xiàn)1844條經(jīng)驗(yàn) 獲得超8個(gè)贊

遍歷resultList檢查以查看當(dāng)前項(xiàng)目是否也在prodRecordsFromStatement.

如果是,則來自文件 1,否則來自文件 2。


查看完整回答
反對(duì) 回復(fù) 2023-05-24
?
HUH函數(shù)

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超4個(gè)贊

您的解決方案需要具備怎樣的性能?如果性能不是非常關(guān)鍵,并且您的列表不長(zhǎng),那么您可以改用 usingsubtract而不是 disjunction。

例如

Collection<String> resultProdRecords = new ArrayList<>(CollectionUtils.subtract(prodRecordsFromStatement, nonProdRecordsFromStatement));
Collection<String> resultNonProdRecords = new ArrayList<>(CollectionUtils.subtract(prodRecordsFromStatement, nonProdRecordsFromStatement));

resultProdRecords將包含 prodRecordsFromStatement 中不在 nonProdRecordFromStatement 中的所有行。

resultNonProdRecords將包含 nonProdRecordFromStatement 中不在 prodRecordsFromStatement 中的所有行。


查看完整回答
反對(duì) 回復(fù) 2023-05-24
  • 2 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)