Java knowledge point summary

Source: Internet
Author: User

1. system. out. println ('H' + 'A'); prints 167 instead of HA, because 'H' and 'A' are both literal constants of the primitive type, a 16-bit unsigned integer of the original type,

It occupies two bytes and can store a single Chinese character, but it is not a string type. When it is used for addition, subtraction, multiplication, division, or greater than or equal to the comparison, it is extended to the int type for calculation.

 
Char [] C = ['1', '2', '3']; system. Out. println ("S" + C );

This will print: s [c @ a90653, because + will call the tostring () method on both sides during string connection. The Char [] array will call the tostring () method of the object,

That is, the memory address format is printed.

2. How to calculate the prime number?

Prime number. In a natural number greater than 1, except for 1 and the integer itself, it cannot be any number of other natural number integers.

 
Public static Boolean isprim (INT number) {Boolean isprim = true; int K = (INT) math. SQRT (number); // the square root of the number, and then use number to divide the number smaller than the square root greater than 2 to check whether the for (INT I = 2; I <= K; I ++) {If (Number % I = 0) {isprim = false; break;} return isprim ;}

3. Compile a buddle method to sort the numbers in string a = "55674683421998" in ascending order.

Method 1: Use the built-in arrays. Sort () sorting method

String A = "55674683421998"; char [] d = A. tochararray (); arrays. Sort (d); system. Out. println (new string (d ));

Method 2:

 
Public static string buddle (string a) {char [] S =. tochararray (); For (INT I = 0; I <S. length; I ++) {for (Int J = 0; j> S. length-i-1; j ++) {If (s [J]> (s [J + 1]) {char d = s [J + 1]; s [J + 1] = s [J]; s [J] = D ;}}return new string (s );}

4. List and string array Conversion

String Array to list:

 
String [] STR = {"test", "hello", "world"}; List <string> List = new arraylist <string> (); List = arrays. aslist (STR );

List to string array:

 
List <string> List = new arraylist <string> (); string [] tobestored = List. toarray (New String [list. size ()]); // It can be converted into various data arrays. The type is determined during running.

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.