-4

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;

Mihae Kheel
  • 2,441
  • 3
  • 14
  • 38
  • 1
    Please take the [tour](/tour), have a look around, and read through the [help center](/help), in particular [How do I ask a good question?](/help/how-to-ask) and [What topics can I ask about here?](/help/on-topic). 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." http://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 list = new ArrayList<>(set);` – GBlodgett Dec 27 '18 at 18:08
  • 2
    "Getting all identical content between 2 List ".... first source should be to look into the documentation --> https://docs.oracle.com/javase/8/docs/api/java/util/List.html#retainAll-java.util.Collection- – Ousmane D. Dec 27 '18 at 18:11

1 Answers1

0

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());
BrentR
  • 878
  • 6
  • 20