Getting all identical content between 2 List [duplicate]
This question already has an answer here:
Common elements in two lists
10 answers
I am currently able to get the total number of identical string value between my list of string using this.
Set<String> set = new HashSet<>(yourFriendList);
set.addAll(requestModelList.get(getAdapterPosition()).list);
int count = (yourFriendList.size() + requestModelList.get(getAdapterPosition()).list.size()) - set.size());
But now I want to get all of this identical value and put it in a new variable List.
List 1 : a b c d e f g
List 2 : a h i e d j k
identical count is 3
identical string are a d e;
java android arraylist
marked as duplicate by Timothy Truckle, Aomine
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 27 '18 at 18:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Common elements in two lists
10 answers
I am currently able to get the total number of identical string value between my list of string using this.
Set<String> set = new HashSet<>(yourFriendList);
set.addAll(requestModelList.get(getAdapterPosition()).list);
int count = (yourFriendList.size() + requestModelList.get(getAdapterPosition()).list.size()) - set.size());
But now I want to get all of this identical value and put it in a new variable List.
List 1 : a b c d e f g
List 2 : a h i e d j k
identical count is 3
identical string are a d e;
java android arraylist
marked as duplicate by Timothy Truckle, Aomine
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 27 '18 at 18:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. From that second link: "Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it." idownvotedbecau.se/noattempt
– Timothy Truckle
Dec 27 '18 at 18:06
Set stores only non identical entries... You could use some other collections for displaying identical strings however.
– MS90
Dec 27 '18 at 18:07
List<String> list = new ArrayList<>(set);
– GBlodgett
Dec 27 '18 at 18:08
2
"Getting all identical content between 2 List<String> ".... first source should be to look into the documentation --> docs.oracle.com/javase/8/docs/api/java/util/…
– Aomine
Dec 27 '18 at 18:11
add a comment |
This question already has an answer here:
Common elements in two lists
10 answers
I am currently able to get the total number of identical string value between my list of string using this.
Set<String> set = new HashSet<>(yourFriendList);
set.addAll(requestModelList.get(getAdapterPosition()).list);
int count = (yourFriendList.size() + requestModelList.get(getAdapterPosition()).list.size()) - set.size());
But now I want to get all of this identical value and put it in a new variable List.
List 1 : a b c d e f g
List 2 : a h i e d j k
identical count is 3
identical string are a d e;
java android arraylist
This question already has an answer here:
Common elements in two lists
10 answers
I am currently able to get the total number of identical string value between my list of string using this.
Set<String> set = new HashSet<>(yourFriendList);
set.addAll(requestModelList.get(getAdapterPosition()).list);
int count = (yourFriendList.size() + requestModelList.get(getAdapterPosition()).list.size()) - set.size());
But now I want to get all of this identical value and put it in a new variable List.
List 1 : a b c d e f g
List 2 : a h i e d j k
identical count is 3
identical string are a d e;
This question already has an answer here:
Common elements in two lists
10 answers
java android arraylist
java android arraylist
asked Dec 27 '18 at 18:04
Mihae
3511
3511
marked as duplicate by Timothy Truckle, Aomine
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 27 '18 at 18:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Timothy Truckle, Aomine
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 27 '18 at 18:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. From that second link: "Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it." idownvotedbecau.se/noattempt
– Timothy Truckle
Dec 27 '18 at 18:06
Set stores only non identical entries... You could use some other collections for displaying identical strings however.
– MS90
Dec 27 '18 at 18:07
List<String> list = new ArrayList<>(set);
– GBlodgett
Dec 27 '18 at 18:08
2
"Getting all identical content between 2 List<String> ".... first source should be to look into the documentation --> docs.oracle.com/javase/8/docs/api/java/util/…
– Aomine
Dec 27 '18 at 18:11
add a comment |
1
Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. From that second link: "Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it." idownvotedbecau.se/noattempt
– Timothy Truckle
Dec 27 '18 at 18:06
Set stores only non identical entries... You could use some other collections for displaying identical strings however.
– MS90
Dec 27 '18 at 18:07
List<String> list = new ArrayList<>(set);
– GBlodgett
Dec 27 '18 at 18:08
2
"Getting all identical content between 2 List<String> ".... first source should be to look into the documentation --> docs.oracle.com/javase/8/docs/api/java/util/…
– Aomine
Dec 27 '18 at 18:11
1
1
Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. From that second link: "Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it." idownvotedbecau.se/noattempt
– Timothy Truckle
Dec 27 '18 at 18:06
Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. From that second link: "Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it." idownvotedbecau.se/noattempt
– Timothy Truckle
Dec 27 '18 at 18:06
Set stores only non identical entries... You could use some other collections for displaying identical strings however.
– MS90
Dec 27 '18 at 18:07
Set stores only non identical entries... You could use some other collections for displaying identical strings however.
– MS90
Dec 27 '18 at 18:07
List<String> list = new ArrayList<>(set);– GBlodgett
Dec 27 '18 at 18:08
List<String> list = new ArrayList<>(set);– GBlodgett
Dec 27 '18 at 18:08
2
2
"Getting all identical content between 2 List<String> ".... first source should be to look into the documentation --> docs.oracle.com/javase/8/docs/api/java/util/…
– Aomine
Dec 27 '18 at 18:11
"Getting all identical content between 2 List<String> ".... first source should be to look into the documentation --> docs.oracle.com/javase/8/docs/api/java/util/…
– Aomine
Dec 27 '18 at 18:11
add a comment |
1 Answer
1
active
oldest
votes
It sounds like you are describing an intersection between two lists.
This will work:
List<String> list1 = ...
List<String> list2 = ...
List<String> intersection = list1.stream()
.filter(item -> list2.contains(item))
.collect(Collectors.toList());
Then this intersection variable will get all identical value between list 1 and 2?
– Mihae
Dec 27 '18 at 18:16
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It sounds like you are describing an intersection between two lists.
This will work:
List<String> list1 = ...
List<String> list2 = ...
List<String> intersection = list1.stream()
.filter(item -> list2.contains(item))
.collect(Collectors.toList());
Then this intersection variable will get all identical value between list 1 and 2?
– Mihae
Dec 27 '18 at 18:16
add a comment |
It sounds like you are describing an intersection between two lists.
This will work:
List<String> list1 = ...
List<String> list2 = ...
List<String> intersection = list1.stream()
.filter(item -> list2.contains(item))
.collect(Collectors.toList());
Then this intersection variable will get all identical value between list 1 and 2?
– Mihae
Dec 27 '18 at 18:16
add a comment |
It sounds like you are describing an intersection between two lists.
This will work:
List<String> list1 = ...
List<String> list2 = ...
List<String> intersection = list1.stream()
.filter(item -> list2.contains(item))
.collect(Collectors.toList());
It sounds like you are describing an intersection between two lists.
This will work:
List<String> list1 = ...
List<String> list2 = ...
List<String> intersection = list1.stream()
.filter(item -> list2.contains(item))
.collect(Collectors.toList());
answered Dec 27 '18 at 18:11
BrentR
641514
641514
Then this intersection variable will get all identical value between list 1 and 2?
– Mihae
Dec 27 '18 at 18:16
add a comment |
Then this intersection variable will get all identical value between list 1 and 2?
– Mihae
Dec 27 '18 at 18:16
Then this intersection variable will get all identical value between list 1 and 2?
– Mihae
Dec 27 '18 at 18:16
Then this intersection variable will get all identical value between list 1 and 2?
– Mihae
Dec 27 '18 at 18:16
add a comment |
1
Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question? and What topics can I ask about here?. From that second link: "Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it." idownvotedbecau.se/noattempt
– Timothy Truckle
Dec 27 '18 at 18:06
Set stores only non identical entries... You could use some other collections for displaying identical strings however.
– MS90
Dec 27 '18 at 18:07
List<String> list = new ArrayList<>(set);– GBlodgett
Dec 27 '18 at 18:08
2
"Getting all identical content between 2 List<String> ".... first source should be to look into the documentation --> docs.oracle.com/javase/8/docs/api/java/util/…
– Aomine
Dec 27 '18 at 18:11