New Features of jdk1.7

Source: Internet
Author: User

1. You can use a string in the switch.

In earlier versions, data of the string type in the switch statement block is not supported. This function has long been supported in C #. Fortunately, jdk1.7 is added.

String S = "test";Switch(S ){Case"Test": System. Out. println ("Test");Case"Test1": System. Out. println ("Test1");Break;Default: System. Out. println ("Break");Break;}

2. Automatic Inference of generic instantiation types

List <string> templist =NewArraylist <> ();

3. Enhanced support for Java collections

In versions earlier than jdk1.7, the form of access elements in Java Collection containers is as follows.ToList,Set,MapThe collection container is used as an example:

 //  Create a list interface object List <string> List = New Arraylist <string> (); List. Add ( "Item ");//  Use the add () method to obtain an object String item = list. Get (0 ); //  Get object using get () method  //  Create a set interface object Set <string> set = New Hashset <string> (); Set. Add ( "Item "); //  Add an object using the add () method  //  Create a map interface object Map <string, integer> map = New Hashmap <string, integer>(); Map. Put ( "Key", 1 ); //  Add an object using the put () method  Int Value = map. Get ("key ")

In jdk1.7, Java Collection interface implementation classes are discarded, such as arraylist, hashset, and hashmap. Instead, the object is saved in the form of [] and {}, and the object in the set is obtained in the form of [] according to the index and key value, as follows:

List <string> List = ["item"];//Add an element to a list setString item = list [0];//Retrieve elements from the list setSet <string> set = {"item "};//Add an element to a set objectMap <string, integer> map = {Name: "XXX", age: 18};//Add objects to the map setIntValue = map ["Age"];//Get objects from the map set

4. New tools and methods for retrieving Environment Information

File System. getjavaiotempdir ()//Io Temporary FolderFile System. getjavahomedir ()//JRE installation directoryFile System. getuserhomedir ()//Current user directoryFile System. getuserdir ()//Directory where the JAVA process is started......

5. boolean type inversion, null pointer security, and bit operation

 //  Type inversion, null pointer Security Boolean booleans. Negate (Boolean booleanobj) //  True => false, false => true, null => null  // Involved in bitwise operation  Boolean Booleans. And ( Boolean  [] Array)  Boolean Booleans. Or ( Boolean  [] Array)  Boolean Booleans. XOR ( Boolean  [] Array)  Boolean  Booleans. And (Boolean [] array)  Boolean  Booleans. Or (Boolean [] array) Boolean Booleans. XOR (Boolean [] array)

6. Equals between two char

 
BooleanCharacter. equalsignorecase (CharSuccess,CharCH2)

7. Safe addition, subtraction, multiplication, division

 Int Math. safetoint ( Long  Value)  Int Math. safenegate ( Int  Value)  Long Math. safesubtract (Long Value1, Int  Value2)  Long Math. safesubtract ( Long Value1, Long  Value2)  Int Math. safemultiply ( Int Value1, Int  Value2)  Long Math. safemultiply ( Long Value1, Int Value2)  Long Math. safemultiply ( Long Value1, Long  Value2)  Long Math. safenegate ( Long  Value)  Int Math. safeadd ( Int Value1, Int  Value2)  Long Math. safeadd ( Long Value1,Int  Value2)  Long Math. safeadd ( Long Value1, Long  Value2)  Int Math. safesubtract ( Int Value1, Int Value2)

8. The value can be underlined.

 
IntOne_million = 0000000_000;

9. Support for binary text

 
IntBinary = 0b1001_1001;

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.