0

i have two generic value of type emp and principle emp pojo

class emp
{
  Private String name;
  Private String Phone;
  Private Designation;
  //setters and getters
}

principle pojo

class principle
{
  Private String name;
  Private String lastName;
  Private String school;
  //setters and getters
}

I am having two list

List<emp> list=new ArrayList<emp>();
list=dao.getData();

List<principle> list1=new ArrayList<principle>();
list1=dao.getDataOfprinciple();

i have tried something like this

List<emp> list3=new ArrayList<emp>();
    for(emp e:list)
        {
            for(principle p:list1)
            {
                String x=e.getName();
            String y=p.getName();
            if(x==y)
            break;
            Reader reader=new Reader();
                reader.setMfrPn(r.getMfrPn());  
                reader.setMfrName(r.getMfrName());  
            list3.add(r);   
            }
           }

how do I find the list of emp which are not matching with principle list with respect to name and I have to store the list in new list of type emp

NITISH
  • 155
  • 2
  • 15
  • What does this have to do with generics? Why are you creating lists and discarding them? Why don't you follow Java naming conventions? – shmosel Aug 10 '17 at 06:06
  • That answers 0 questions. – shmosel Aug 10 '17 at 06:12
  • can i use nested for each – NITISH Aug 10 '17 at 06:20
  • Why don't you try? – shmosel Aug 10 '17 at 06:20
  • I'm happy to help, but I don't intend to write free code for you. That's not how this site works. And I wasn't pointing out mistakes so much as clarifying and suggesting. – shmosel Aug 10 '17 at 06:24
  • thanks for your suggestions sir – NITISH Aug 10 '17 at 06:35
  • You're on the right track, but you're adding too soon. You have to wait for the inner loop to complete first. One option is to add it after the inner loop and `continue outer;` if a match is found. Or you can do `List list3 = list.stream().filter(e -> list1.stream().noneMatch(e.getName()::equals)).collect(Collectors.toList());` – shmosel Aug 10 '17 at 06:41
  • Also, [don't use `==` to compare strings](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java). – shmosel Aug 10 '17 at 06:42
  • Correction to the above: `list1.stream().map(principle::getName)` – shmosel Aug 10 '17 at 06:53

0 Answers0