Home > Back-end >  LIST objects to weight problems
LIST objects to weight problems

Time:03-03


No points, so I can only set this some

I have one to like aa there are three attributes name1, name2, name3, age and sex

LIST Temp=new array ();

The temp there are 1000 data
I want to do is now, if there are two records:, name1 name2, name3 is one, is considered a duplicate data. I want to take out to

Now can't use Java 8 steam, efficient logical way?

This is the cycle of 1000 * 1000 has a little low


CodePudding user response:

The name that a few field stitching as a HashMap key, determine whether there are key, should cycle can come out again

CodePudding user response:

This decisive in the stream, direct temp. Stream. The filter (aa: : name1) equals (aa: : name2) & amp; & Aa: : name3 equals (aa: : name2).). Collect (Collectors. ToList ());

CodePudding user response:

Originally I also is to use steam, quick and province code

The last server JDK not above 1.8, cannot use the

Now, in writing,

By the way,

CodePudding user response:

Rewrite the aa hashCode equals, the list Set, and then turned back to the list

CodePudding user response:

Turn the list set, and then turned back to the list, the set automatically to heavy

CodePudding user response:

reference 1st floor hbhbhbhbhb1021 response:
the name that a few field stitching as a HashMap key, to determine whether there are key, should cycle can again come out
yes, you can again

CodePudding user response:

4th floor is the solution, try to know

CodePudding user response:

What you need is to filter out duplicate elements, or remove duplicate elements?

If is filtered out, with the Set directly, do not use the list,

If it is out in the following logical

The arraylist inside elements according to name1 name2, name3 order, and then traverse, if the second element nam1, name2, name3 is equal to the value of an element, add him to the new set inside, finally return to the new set.
  • Related