Re: [問題]set method

看板java作者 (沉默是金)時間17年前 (2008/07/07 18:05), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《hsnucsc (hsnugo)》之銘言: : 請問java有什麼class可以做到像 : { 1 , 2 , 3} 交集 { 2 ,4} => {1,2,3,4} : { 1 , 2 , 3} - { 2 ,4} => {1,3} : 我看collection裡的set hashset treeset : 好像都沒有這樣的method : 還是有什麼好方法可以做到呢 : 感謝 你可以用HashSet做到 假設 HashSet A,B , 假設 A ={1,2,3} B={2,4} 你可以寫個HashSetUtil 加法的部分 HashMap c= new HashMap(A); //一定要用複製,不然A會被影響. c.addAll(b); //得到 a+b的結果 減法 HashMap c= new HashMap(A); //一定要用複製,不然A會被影響. c.removeAll(b); //得到 a-b的結果 根據Set add的時候會過濾相同值的特色,來達到目標> -- I am a person, and I am always thinking . Thinking in love , Thinking in life , Thinking in why , Thinking in worth. I can't believe any of what , I am just thinking then thinking , but worst of all , most of mine is thinking not actioning... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.128.219.202 ※ 編輯: TonyQ 來自: 220.128.219.202 (07/07 18:05)
文章代碼(AID): #18SUfNVk (java)
討論串 (同標題文章)
本文引述了以下文章的的內容:
問題
6
9
完整討論串 (本文為第 2 之 2 篇):
問題
6
9
文章代碼(AID): #18SUfNVk (java)