JAVA8有什么新的特性?

JAVA8是JAVA编程语言开发的一大特色版本。它的最初版本发布于2014年3月18日。使用Java8版本,提供Java支持功能编程,新的JavaScript引擎,日期时间操作,新的流API等新API。

新功能

  • Lambda 表达式 - 增加函数处理能力到JAVA。

  • 方法引用 - 引用函数由他们名称,而不是直接调用它们。使用函数的参数。

  • 默认方法 - 接口有默认的方法实现。

  • 新工具 - 新的编译器工具和实用程序被添加,如jdeps找出依赖。

  • 数据流API - 新数据流的API,以方便数据流处理。

  • 日期时间API - 改进日期时间API。

  • 可选- 强调最佳实践,妥善处理空(null)值。

  • Nashorn , JavaScript引擎 - 一个基于JAVA引擎执行JavaScript代码。

考虑下面的代码片段。

  import java.util.Collections;  import java.util.List;  import java.util.ArrayList;  import java.util.Comparator;    public class Java8Tester {       public static void main(String args[]){        List<String> names1 = new ArrayList<String>();        names1.add("Mahesh ");        names1.add("Suresh ");        names1.add("Ramesh ");        names1.add("Naresh ");        names1.add("Kalpesh ");          List<String> names2 = new ArrayList<String>();        names2.add("Mahesh ");        names2.add("Suresh ");        names2.add("Ramesh ");        names2.add("Naresh ");        names2.add("Kalpesh ");          Java8Tester tester = new Java8Tester();          System.out.println("Sort using Java 7 syntax: ");              tester.sortUsingJava7(names1);        System.out.println(names1);                  System.out.println("Sort using Java 8 syntax: ");              tester.sortUsingJava8(names2);        System.out.println(names2);     }       private void sortUsingJava7(List<String> names){        //sort using java 7        Collections.sort(names, new Comparator<String>() {           @Override           public int compare(String s1, String s2) {              return s1.compareTo(s2);           }        });     }       private void sortUsingJava8(List<String> names){        //sort using java 8        Collections.sort(names, (s1, s2) ->  s1.compareTo(s2));           }  }

运行程序, 看到结果。

  Sort using Java 7 syntax:   [ Kalpesh Mahesh Naresh Ramesh Suresh ]  Sort using Java 8 syntax:   [ Kalpesh Mahesh Naresh Ramesh Suresh ]  

在这里,sortUsingJava8()方法使用排序功能使用一个lambda表达式作为参数,以获得排序条件。


本文属作者原创,转载请注明出处:易百教程 » Java8教程

812阅读 | 0评论
你的回应
  • owiwaci

    2019-08-11 15:43:17 owiwaci

    Emergency nnw.axxb.osbaike.net.txd.mb inadvertent [URL=http://discoveryshows.com/cialis-soft/]buy cialis soft[/URL] cialis soft lowest price [URL=http://gaiaenergysystems.com/dapoxetine/]priligy[/URL] [URL=http://discoveryshows.com/viagra-soft/]viagra soft online[/URL] [URL=http://elegantearthatthearbor.com/valtrex-online/]valtrex neck ache[/URL] [URL=http://vintagepowderpuff.com/viagra-online/]buy viagra online[/URL] viagra for sale [URL=http://davincipictures.com/kamagra/]buy kamagra online[/URL] [URL=http://earthbeours.com/cialis-canadian-pharmacy/]generic cialis canadian pharmacy[/URL] [URL=http://davincipictures.com/viagra-buy-in-canada/]cheep viagra[/URL] enhancing warm, cialis soft lowest price priligy dapoxetine order viagra soft online valtrex online viagra cheap kamagra buy cialis online canada pharmacy generic viagra 50 mg hidden http://discoveryshows.com/cialis-soft/ cialis soft http://gaiaenergysystems.com/dapoxetine/ dapoxetine online http://discoveryshows.com/viagra-soft/ viagra soft online http://elegantearthatthearbor.com/valtrex-online/ valtrex online valtrex online http://vintagepowderpuff.com/viagra-online/ viagra for sale http://davincipictures.com/kamagra/ kamagra http://earthbeours.com/cialis-canadian-pharmacy/ on line pharmacy http://davincipictures.com/viagra-buy-in-canada/ v

  • abmirecafiuma

    2019-08-03 22:57:41 abmirecafiuma

    The ifl.rsjk.osbaike.net.hgg.gj oesophagectomy; periosteal [URL=http://washingtonsharedparenting.com/lisinopril/]personal injury lisinopril[/URL] [URL=http://jacksfarmradio.com/ventolin-inhaler-for-sale/]ventolin inhaler[/URL] [URL=http://buckeyejeeps.com/super-kamagra/]super kamagra generic[/URL] [URL=http://bikramcentennial.com/indocin/]indocin colchicine[/URL] [URL=http://puresportsnetwork.com/pharmacy/]pharmacy[/URL] [URL=http://mrcpromotions.com/rulide/]online rulide[/URL] [URL=http://fitnesscabbage.com/cialis-com-lowest-price/]cialis tadalafil 20 mg ta

  • ukudalvuwope

    2019-07-23 21:40:42 ukudalvuwope

    Other qjb.qdng.osbaike.net.avb.yh space-occupying [URL=http://timoc.org/viagra-online/]viagra.com[/URL] [URL=http://nicaragua-magazine.com/viagra-100mg/]viagra canada[/URL] [URL=http://nicaragua-magazine.com/viagra/]viagra[/URL] [URL=http://timoc.org/prednisone-20-mg/]prednisone[/URL] [URL=http://earthbeours.com/viagra-generic/]viagra[/URL] [URL=http://nicaragua-magazine.com/viagra-online/]viagra 100mg price walmart[/URL] [URL=http://dead-fish.com/buy-cialis/]cialis online[/URL] [URL=http://thebestworkoutplan.com/tadalafil-20-mg/]buy tadalafil online[/URL] cialis generic 20 mg [URL=http://nicaragua-magazine.com/cialis-20-mg/]cialis.com[/URL] irrespective viagra for sale viagra canada cheap viagra deltasone and pregnancy category cheap viagra pills canadian viagra cialis prezzo farmacia cialis lowest price for cialis 20 mg cialis 20 mg fasciculus non-pregnant parasite http://timoc.org/viagra-online/ viagra generic paypal http://nicaragua-magazine.com/viagra-100mg/ viagra on line http://nicaragua-magazine.com/viagra/ buy viagra online http://timoc.org/prednisone-20-mg/ prednisone 10 mg http://earthbeours.com/viagra-generic/ online viagra http://nicaragua-magazine.com/viagra-online/ viagra online http://dead-fish.com/buy-cialis/ cialis from canada http://t

  • enuuxadled

    2019-07-12 08:47:21 enuuxadled

    It xpu.gfhw.osbaike.net.bev.ov conducting [URL=http://heavenlyhappyhour.com/fluoxetine/]fluoxetine lowest price[/URL] [URL=http://quotes786.com/vidalista/]potenzmittel ginerika vidalista[/URL] [URL=http://iowansforsafeaccess.org/tadalafil-20-mg/]cialis 20 mg[/URL] [URL=http://disclosenews.com/revia/]price of revia[/URL] [URL=http://heavenlyhappyhour.com/vidalista/]vidalista[/URL] [URL=http://bootstrapplusplus.com/cialis-5mg/]cialis 10mg[/URL] [URL=http://thefashionhob.com/cheap-cialis/]cialis[/URL] [URL=http://quotes786.com/cialis-professi

  • iminasayatxi

    2019-06-29 21:17:11 iminasayatxi

    Some fio.aarx.osbaike.net.dmz.xg dread overhearing tarso-metatarsal [URL=http://quotes786.com/cialis-professional/]cialis professional without dr prescription[/URL] [URL=http://dive-courses-bali.com/prednisone/]buy prednisone online in us[/URL] [URL=http://thefashionhob.com/cialis-20-mg-price/]how many mg does cialis come in[/URL] [URL=http://livetvchannels.org/viagra-super-active/]viagra super active[/URL] [URL=http://tattoosideasblog.com/cialis-online/]cialis online[/URL] [URL=http://quotes786.com/eriacta-for-sale/]eriacta[/URL] [URL=http://heavenlyhappyhour.com%

  • uqeboxaloquc

    2019-06-26 22:34:04 uqeboxaloquc

    To oah.msli.osbaike.net.nmq.pe whooping [URL=http://quotes786.com/vidalista/]discount vidalista[/URL] [URL=http://heavenlyhappyhour.com/vidalista/]vidalista 20 recensioni[/URL] [URL=http://bootstrapplusplus.com/lasix/]lasix[/URL] [URL=http://solartechnicians.net/lyrica/]lyrica[/URL] [URL=http://alwaseetgulf.com/tadalafil-20-mg/]cialis[/URL] headedness, lower-third tamponade vidalista vidalista without a prescription

  • amuyuezuwu

    2019-06-13 14:17:45 amuyuezuwu

    Ewing's tfb.bbwr.osbaike.net.jyj.ds headaches, coarse, [URL=http://vintagepowderpuff.com/cash-advance/]cash advance[/URL] [URL=http://bootstrapplusplus.com/argumentative-essay/]politics essay[/URL] [URL=http://circulateindia.com/same-day-loans/]same day loans[/URL] [URL=http://thegrizzlygrowler.com/essay-writer/]explanatory synthesis essay[/URL] [URL=http://bootstrapplusplus.com/write-my-essay-for-me/]obesity essay[/URL] [URL=http://myquickrecipes.com/personal-loan/]payday loans no credit check[/URL] dry sulphate,

  • uhoiyoluxezip

    2019-06-03 20:07:58 uhoiyoluxezip

    C7 jrx.hjbr.osbaike.net.xyn.nd hundreds [URL=http://anguillacayseniorliving.com/viagra-com/]viagra[/URL] [URL=http://anguillacayseniorliving.com/cialis-online/]subaction showcomments cialis thanks online[/URL] [URL=http://washingtonsharedparenting.com/renova--for-sale/]renova[/URL] [URL=http://anguillacayseniorliving.com/buy-cialis/]cialis price[/URL] [URL=http://tofupost.com/cialis/]tadalafil tablets 20 mg[/URL] [URL=http://tacticaltomahawkreviews.com/valtrex/]valtrex online[/URL] [URL=http://pintlersuites.com/viagra-professional/]viagra professional for sale[/URL] %5

  • adeneru

    2019-05-30 14:14:42 adeneru

    D; ilg.mbom.osbaike.net.xjc.lv surrounds [URL=http://anguillacayseniorliving.com/prednisone/]prednisone 20 mg side effects[/URL] buy prednisone without prescription [URL=http://gaiaenergysystems.com/buy-accutane-online/]accutane on line[/URL] [URL=http://foodfhonebook.com/sildalis/]sildalis canada[/URL] [URL=http://washingtonsharedparenting.com/ventolin-inhaler/]adimmix ventolin inhaler online[/URL] [URL=http://foodfhonebook.com/brand-viagra/]brand viagra for sale[/URL] brand viagra without a prescription [URL=http://infaholic.com/propecia-online/]propecia finasteride[/URL] finasteride no prescription [URL=http://anguillacayseniorliving.com/buy-viagra/]viagra generic[/URL] [URL=http://gaiaenergysystems.com/viagra-pills/]lowest price for viagra 100mg[/URL] tear's delicate by prednisone w not prescription accutane online sildalis ventolin inhaler without a prescription brand viagra without a prescription buy finasteride online viagra for cheap ajanta kamagra concerned, started http://anguillacayseniorliving.com/prednisone/#prednisone prednisone online prednisone no presciption http://gaiaenergysystems.com/buy-accutane-online/#generic-accutane accutane online http://foodfhonebook.com/sildalis/#sildalis-lowest-price sildalis online http://washingtonsharedparenting.com/ventolin-inhaler/#online-ventolin-inhaler spanish instructions ventolin inha

  • uxawielirahit

    2019-05-22 07:12:09 uxawielirahit

    Venous fmr.icmw.osbaike.net.lhp.do plotting practitioners fundus [URL=http://gccroboticschallenge.com/generic-cialis/]tadalafil 20mg[/URL] generic cialis tadalafil [URL=http://scoverage.org/buy-cialis/]buy cialis on line[/URL] [URL=http://a1sewcraft.com/cialis-on-line/]cialis 20 mg lowest price[/URL] [URL=http://ekautorepair.com/accutane/]buy accutane online[/URL] [URL=http://a1sewcraft.com/discount-viagra/]viagra generic[/URL] viagra generic [URL=http://discoveryshows.com/lyrica/]cheapest lyrica[/URL] [URL=http://columbiainnastoria.com/buy-cialis-online/]c

1 2345
联系我们