Java Data types

Source: Internet
Author: User

1, basic data type

Type

The space occupied

Range

Description

Byte

1

-128~127

Short

2

-215~-215-1

Int

4

-231~-231-1

Default integral type

Long

8

-263~-263-1

End plus L

Float

4

-3.403e38~3.403e38

End plus F

Double

8

-1.798e308~1.798e308

Default decimal type

Char

2

Support Chinese

Boolean

True/false

2, reference data type

The stack memory points to the heap memory, and if multiple stacks point to the same heap, then any one stack modifying the heap contents will affect the other stacks

Java has three types of reference data: Class, interface, array

3, String

String: Immutable, each time a change is made to the string class, it is a new instance, changing the pointer's point

StringBuilder: variable, thread insecure

StringBuffer: variable, thread-safe

three in the execution efficiency : StringBuilder > StringBuffer > String

StringBuilder and StringBuffer do not have contains (), concat (), Endswidth (), Startwidth (), Matches (), ReplaceAll (), Replacefirst (), substring (), split (), Trim ()

string Common methods :

char charAt (int index): Returns the char of the specified subscript

String concat (String str): stitching strings to the end

Boolean endswidth (String str): Whether to end with the specified string

Boolean equals (Object obj): Compare with an object

Boolean contentequals (String str): Compare to a string

Bytes[] GetBytes (): Returns a byte array

int indexOf (String str): The first occurrence of subscript

int lastIndexOf (String str): Last occurrence of subscript

int length (): Number of strings

Boolean matches (String reg): Comparison with a regular, match succeeds return true, reverse returns false

String Replace (string oldstr, String newstr): Replaces all oldstr with NEWSTR, returns a new string

String ReplaceAll (String Reg, String newstr): Replaces all Reg with NEWSTR, and the difference between replace is support for regular

String Replacefirst (String Reg, String newstr): Replaces the first character, supports regular

String[] Split (String reg): Splits the string with the specified characters, returns a string array, supports regular

Boolean stratwidth (String str): Whether it is the beginning of str

string substring (int start, int end): Intercept string, front closed

Char[] ToCharArray (): Returns an array of characters

String toLowerCase (): Turns lowercase

String toUpperCase (): Turn into uppercase

String trim (): Go to Space

Static string ValueOf (Var): Turns Var into a string

Common methods of StringBuilder and StringBuffer:

Append (String str): Append at end

ToString (): Turn into string

Setcharat (int index, char c): replaces the specified subscript character, not the string is char

Insert (int index, string str): Inserts a string before specifying subscript

Delete (int index, int end): Delete string, front closed

Java Data types

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.