[DataStructure] Charming usage of Set in the java, thecharmingman

Source: Internet
Author: User

[DataStructure] Charming usage of Set in the java, thecharmingman

In an attempt to remove duplicate elements from list, I go to the lengths to take advantage of methods in the java api. after investiagting the document of java api, the result is so satisfying that I speak hightly of wisdom of developer of java language. next I will introduce charming usage about set in the java.

[Java]View plaincopy
  1. Import java. util. ArrayList;
  2. Import java. util. Arrays;
  3. Import java. util. Collections;
  4. Import java. util. HashSet;
  5. Import java. util. List;
  6. Import java. util. Set;
  7. Import java. util. TreeSet;
  8. Public class SetUtil
  9. {
  10. Public static List <String> testStrList = Arrays. asList ("Apple", "Orange ",
  11. "Pair", "Grape", "Banana", "Apple", "Orange ");
  12. /**
  13. * Gets sorted sets which contains no duplicate elements
  14. *
  15. * @ Time Jul 17,201 4 7:58:16
  16. * @ Return void
  17. */
  18. Public static void sort ()
  19. {
  20. Set <String> sortSet = new TreeSet <String> (testStrList );
  21. System. out. println (sortSet );
  22. // Output: [Apple, Banana, Grape, Orange, Pair]
  23. }
  24. Public static void removeDuplicate ()
  25. {
  26. Set <String> uniqueSet = new HashSet <String> (testStrList );
  27. System. out. println (uniqueSet );
  28. <Span style = "font-family: Arial, Helvetica, sans-serif;"> // output: </span> <span style = "font-family: Arial, Helvetica, sans-serif; "> [Pair, Apple, Banana, Orange, Grape] </span>
  29. }
  30. Public static void reverse ()
  31. {
  32. Set <String> sortSet = new TreeSet <String> (testStrList );
  33. List <String> sortList = new ArrayList <String> (sortSet );
  34. Collections. reverse (sortList );
  35. System. out. println (sortList );
  36. // Output: [Pair, Orange, Grape, Banana, Apple]
  37. }
  38. Public static void swap ()
  39. {
  40. Set <String> sortSet = new TreeSet <String> (testStrList );
  41. List <String> sortList = new ArrayList <String> (sortSet );
  42. Collections. swap (sortList, 0, sortList. size ()-1 );
  43. System. out. println (sortList );
  44. Output: [Apple, Orange, Grape, Banana, Pair]
  45. }
  46. Public static void main (String [] args)
  47. {
  48. SetUtil. sort ();
  49. SetUtil. reverse ();
  50. SetUtil. swap ();
  51. SetUtil. removeDuplicate ();
  52. }
  53. }

Q: Is The use of generic with The usage? The following sentence

The use of... is understood as "application ...."
The usage of... emphasizes usage
We recommend that you use the use...

Sentence:
It is greatly significant that ....
It is a formal subject, and the subject clause guided by that is a real subject. that cannot be omitted.
Great must be greatly, and the adjective significant must be modified with an adverbs.
You should use adj. significant because the structure of the primary table is used here. It indicates the state of the event by using adj as a table.
For example:
I am hungry. I am hungry should be used instead of I am hunger)

If you want to use the noun significance, you need to change the sentence structure, for example
There is a great significance that ....
There be + subject. The subject should use a noun. At this time, that directs the sentence clause. The meaning of a sentence is the same as that of it is.

Usage of the word fuck ~

In modern English, "FUCK" is probably the most interesting word. "Fuck" is the only English word labeled as "F. The magic of this word is that it can express pain, happiness, disgust, and love by its pronunciation alone. Like most other English words, Fuck is transformed from a German word that means "blow.
In English, Fuck is divided into multiple syntax classes. It can be used as a thing-and-object verb, for example, "John Fucked Shirley ). It can also be used as an inactive verb, 'Shirley Fucks '(Shirley goes to bed ). It doesn't always mean sex. It can be used as an adjective, for example, 'John's doing all the Fucking work' (John is doing all the annoying work ). In part, we can say 'Shirley talks too Fucking much' (Shirley said too much ). In this way, when it is an adverbs and adjective, it can be used to strengthen the tone of speech. For example, 'Shirley is Fucking beauul ul '(Shirley is so beautiful ). As a noun, you can use 'I don't give a Fuck' separately .). It can also be used as part of a word 'abso-Fucking-lutely ''' in-Fucking-credible '. You can also use it 'Fuck the Fucking fuckers' in one sentence ).
You must realize that there are few words that can be as widely used as Fuck. Like in these examples:
Fraud: 'I got Fucked at the car dealership' (I was cheated by car dealers)
Disappointment: 'Oh Fuck it' (enough)
Trouble: 'I guess I'm already dizzy)
Popular: Don't Fuck with me pal (Don't provoke me)
Difficulty: 'I don't understand this Fucking question' (I don't understand this nasty problem)
Question: 'Who the Fuck was that? '(Who the hell is it ?)
Not satisfied: 'I don't like what the Fuck is going on here' (I don't like what is happening)
Incompetent: He's a Fuck up (He is useless)
Hurry up: Why don't you go outside and play hide and go Fuck yourself? (Why don't you go out and play hide-and-seek and fuck yourself ?)
I'm sure you can think of more examples. Since there is such a multi-purpose word, how can someone be offended by your use of this word? I said that everyone should use this word in their lives. He will immediately display your character.
Say it
Proud!-x your mom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.