2016/04/14

Source: Internet
Author: User
Tags time in milliseconds

Common classes

One. System

System runs the platform on behalf of the Java program

The System is a fianl class, so the properties are static

Common methods:

Currenttimemillis (); Returns the current time in milliseconds starting from 1970-01-01

Long a = System.currenttimemillis ()/1000/60/60/24/365+1970;
SYSTEM.OUT.PRINTLN ("Current year is:" +a); Can figure out the current year

System.exit(0); 终止Java虚拟机(直接停止程序  不推荐使用)/renturu 也能终止执行方法 推荐使用 renturn

GetProperties (); Determine System Current properties

GC (); Represents garbage collection

Reference technology algorithm (refetence counting)

Root Search algorithm (Gc Roots tracing)

Tag-purge algorithm: First mark the garbage to be reclaimed and then remove the disadvantage: it will cause a lot of fragmentation in memory

Copy algorithm: Put the things you want to clean aside and not be clear on one side can be well cleared and does not create fragmentation in memory disadvantages: turning memory into half

Tagging-sorting algorithm: Dynamically putting things aside to be erased does not halve memory advantage: The first two algorithms are more user-friendly

Runtime class

Its method:

Rt.availableprocessors (); Current number of processors

Rt.freememory (); Number of free memory

Rt.totalmemory (); Total amount of memory

Rt.maxmemory (); Maximum number of memory

string-related class string

= = Object when the memory address is determined to be equal

Method:

Length ();

CharAt (); Returns the index char value

CompareTo (); Compare strings in dictionary order

Concat (); concatenation of strings

Contains (); Determine if a string contains a character

GetBytes (); Converts the string to a byte type based on the default character encoding of the platform

IndexOf (); Returns the subscript of a character in a string

IsEmpty (); Determine if it is empty

Split (); splitting a string

toLowerCase (); Convert a string to lowercase

toUpperCase (); Convert a string to uppercase

Trim (); Ignore front and back spaces (middle can't ignore)

replace (); Replaces the contents of a string

SUBSTRING (); Returns a new string from the beginning of the first intercept to the end position of a character

The value inside the String is not changed and the length cannot be modified.

Import Java.lang.reflect.Array;
Import Java.util.Arrays;
/***
*
* @author Administrator
* String Related classes
*/

public class Stringclass {

public static void Main (string[] args) {
String s = "ABCD";
System.out.println (S.charat (1));
S.charat (1) Searches for a string that corresponds to a character that returns the char value at the specified index.


--------------------------the split line June------------------------------------------
String s = "abc";
String S1 = "DEFG";
System.out.println (S1.compareto (s));
CompareTo Comparing strings in dictionary order if the previous string is greater than the last string is positive instead of negative


--------------------------the split line June------------------------------------------
String s = "abc";
String S1 = "DEFG";
System.out.println (S.concat (S1));
Concat string concatenation


--------------------------the split line June------------------------------------------
String s = "qwe";
System.out.println (S.contains ("1"));
Contains to determine if a character is contained in a string is returned true not to return false


--------------------------the split line June------------------------------------------
String s = "ABCDEFG";
System.out.println (S.getbytes ());
GetBytes converts the string to a byte type based on the default character encoding of the platform
System.out.println (Arrays.tostring (S.getbytes ()));
Arrays.tostring the result into a new array


--------------------------the split line June------------------------------------------
String s = "abc";
System.out.println (S.indexof ("C"));
IndexOf returns the subscript of the specified character in the string if it doesn't, he'll return 1.


--------------------------the split line June------------------------------------------
String s = "AAA";
System.out.println (S.isempty ());
IsEmpty to determine if the string is empty? Yes returns true not return False


--------------------------the split line June------------------------------------------
★ Difficulty
String s = "a:b:c:d:e:f:g";
System.out.println (Arrays.tostring (S.split (":", 6));
Arrays.tostring the result into a new array
Split splitting string

For example, the string "Boo:and:foo" uses these parameters to produce the following results:
Regex Limit Results
: 2 {"Boo", "And:foo"}
: 5 {"Boo", "and", "foo"}
:-2 {"Boo", "and", "foo"}
o 5 {"B", "", ": And:f", "", ""}
o-2 {"B", "", ": And:f", "", ""}
o 0 {"B", "", ": And:f"}


--------------------------the split line June------------------------------------------
String s = "ACDEFG";
String s1= "ABCDEFG";
System.out.println (S.touppercase ());
System.out.println (S1.tolowercase ());
toUpperCase convert characters to uppercase
toLowerCase convert characters to lowercase


--------------------------the split line June------------------------------------------
String s = "ADC";
System.out.println (S.trim ());
String S1 = "ADC";
System.out.println (S1.trim ());
String s2 = "a D c";
System.out.println (S2.trim ());
Trim ignores whitespace before and after a string (the space in the middle cannot be ignored)


--------------------------the split line June------------------------------------------
String s = "ABCDEFG";
System.out.println (S.replace ("C", "0"));
Replace changes the contents of the string to the model: replace ("the character that needs to be changed", "the character you want to change to")


--------------------------the split line June------------------------------------------
String s = "ABCDEFGHIJKLMN";
System.out.println (s.substring (0, 5));//Run Result: ABCDE
SUBSTRING returns a new string from the beginning of the first intercept to the end position of a character
SUBSTRING (0 of the first character subscript, 5 intercept the end of the subscript but not intercept the fifth but intercept the previous character)

}
}

StringBuffer (can grow string)

StringBuffer a = StringBuffer ();//Create a string that can be spliced

Method:

Insert (); Append character to multi-string/specified place

Append (); Always add characters to the end of the buffer


public class Stringbufferclass {

public static void Main (string[] args) {
StringBuffer sb = new StringBuffer ();
Sb.append ("12345");
Sb.append ("6789");
Sb.append ("Lalala");
Sb.insert (5, "KK");
System.out.println (SB);//Last Run Result: 12345kk6789lalala
Append always adds the specified character to the end of the buffer
Insert (5 Plus to subscript 5) Note that the subscript starts at zero, and "KK" indicates the need to add

Added characters)
Insert to add characters to the specified location
}
}

String Builder Class

He's a light-weight version of StringBuffer.

Performance: stringbuilder> stringbuffer>string

StringBuilder thread is unsafe stringbuffer thread safety

Date related classes

Date--javautil

The default method of the Date class does not apply to our

GetYear (); A horizontal line indicates that it is not recommended because you will encounter the millennium bug problem

SimpleDateFormat date Formatting

Model:

SimpleDateFormat a = new SimpleDateFormat ("yyyy-mm-hh");

A.format (); Converts date to a conforming string type ("Yyyy-mm-hh")

A.parse (); String string converted to date

The Calendar class is an abstract class

Model: Calender c = new Gregorian calender ();

C.get (calendar.year)/Get specific time

Packing class

The basic data types and reference types are divided into Java

Packaging: Converting the underlying type to a reference type

Why use: Some applications require that the underlying data type must be a reference type

int ——— Packaging ——— > Integer class

Char ——— packaging-Charachter class

int num = 10;
Integer NUM1 = new integer (num);//Packaging Complete manual packaging
Integer num2 = num;//Auto-boxing
Integer anum = 10;
int b = Anum; Automatic unpacking
int b2 = Num1.intvalue ();//Manual unpacking

Why box and unboxing?

① Boxing ———— base data Types ———— reference type reference types there are more ways

② Some operations stipulate that we must use reference types instead of using the underlying data types

Regular expression (pattern)

Indicates an expression that determines whether the user/other data satisfies our expression

Model: Pattern a = new Pattern.compile ("^<------start end of regular expression-----> $");

2016/04/14

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.