Java Basic Knowledge points

Source: Internet
Author: User

Declaring constants:final data type constant name [= value] For example: final double PI = 3.1415926;

Ternary operator: conditional? value 1: Value 2 For example: Boolean b=20 < 45? True:false

For Loop statement: for (expression 1; expression 2; expression 3) where expression 1 is the initialization expression, which is responsible for initialization of the variable, expression 2 is a cyclic conditional expression, a Boolean expression, a loop condition is specified, and expression 3 is a post-loop action expression, Responsible for modifying variables, changing cycle conditions such as: for (int i = 2; I <=; i++) {sum = sum + i}

foreach statement: for (element variable x; Traverse object obj) {Java statement referencing X} for example for (int x; {2,3,4}) {System.out.println (x);}

Break statement, is to jump out of the loop body, continue statement, is to jump out of this loop statement

A concatenated string in Java cannot be written separately in two lines, and need to use + as a connection if necessary: System.out.println ("I like" +

"You");

Get string length using: str.length (); For example, String str = "I love You"; int size = Str.length ();

The IndexOf () method returns the location of the first occurrence of the searched character or string, and the LastIndexOf () method returns the position of the search character or the last occurrence of the string.    Str.indexof (SUBSTR); Str.lastindexof (substr);

Gets the character of the specified index position:str.charat (int index) str: any string. Index: An integer value that specifies the subscript to return the character.

Java Basic Knowledge points

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.