Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept and code of default methods in Java8 default methods

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

< (slices + 1); i++) { Deck currentDeck = deckFactory(); currentDeck.addCards(dealtDeck.get(i)); mapToReturn.put(i, currentDeck); } return mapToReturn; } public String deckToString() { return this.entireDeck.stream().map(Card::toString) .collect(Collectors.joining("\n")); } public String toString(){ return deckToString(); } public static void main(String... args) { System.out.println("Creating deck:"); StandardDeck myDeck = new StandardDeck(); myDeck.sort(); System.out.println("Sorted deck"); System.out.println(myDeck.deckToString()); myDeck.shuffle(); myDeck.sort(new SortByRankThenSuit()); System.out.println("Sorted by rank, then by suit"); System.out.println(myDeck.deckToString()); myDeck.shuffle(); myDeck.sort(Comparator.comparing(Card::getRank).thenComparing( Comparator.comparing(Card::getSuit))); System.out.println("Sorted by rank, then by suit " + "with static and default methods"); System.out.println(myDeck.deckToString()); myDeck.sort(Comparator.comparing(Card::getRank).reversed() .thenComparing(Comparator.comparing(Card::getSuit).reversed())); System.out.println("Sorted by rank reversed, then by suit " + "with static and default methods"); System.out.println(myDeck.deckToString()); myDeck.shuffle(); myDeck.sort( (firstCard, secondCard) ->

FirstCard.getRank (). Value ()-secondCard.getRank (). Value (); System.out.println (myDeck.deckToString ()); myDeck.shuffle (); myDeck.sort (Comparator.comparing (Card::getRank)); System.out.println (myDeck.deckToString ()); Map map=myDeck.deal (4,11) For (Map.Entry item:map.entrySet ()) {System.out.println (item.getKey ()); System.out.println (item.getValue ()); System.out.println ("- -") } on the default method in Java8 default methods concept and code is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report