And basic algorithms commonly used API

And math-related

1, java.lang.Math 类

  • abs (x): absolute value

  • sqrt (x): square root

  • pow (x, y): x to the power demand y

  • ceil (x): rounding up

  • floor (x): rounded down

  • round (x): rounding

  • random (): random number obtained in the range [0,1)

  • max (x, y): find x, the maximum value of y

  • min (x, y): minimization x, y of

  • PI: pi

2,java.Math包

  • BigInteger: not changed, arbitrary-precision integers

  • BigDecimal: immutable arbitrary precision decimal

  • They are to new objects to represent the data, performs arithmetic operation to add, subtract, multiply, divide or the like

3, java.util.Random

Random r = new Random();

r.nextDouble D = Double (); // [0,1)
int I = r.nextInt (); // int within a range
within // [0, x) range; int j = r.nextInt (x) integer

Date and time-related

1 java.util.Date

new Date (): Gets the system date and time

new Date (Long ms): The date and time acquired milliseconds

long getTime (): Get the date and time corresponding to the milliseconds from 1970-1-10: 0: 0

2 java.util.Calender

How to create / acquire objects Calender of?

(1), create a sub-class object: GregorianCalendar

(2) to obtain the specified time zone calendar object

  • getInstance()

  • getInstance (TimeZone time zone) or getInstance (Locale locale)

  • getInstance(TimeZone, Locale)

(3) get (field names)

For example: int year = get (Calendar.YEAR);

 

java.text.DateFormat date and time format

Other sub-categories: SimpleDateFormat

y: Year

M: month

d: day

The first day of the year: D

H: When the 24-hour

h: 12 hour clock

m: min

s: sec

S: ms

E: week

SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

// the date to String
String str = sf.format (Date date of the object);
// parse string date
Date d = sf.parse (string);

java.time 包

1, localized date / time: LocalDate, LocalTime, LocalDateTime

now (): Gets the current date or time

of (x, x, x): Gets a specified date or time

withXxx (), plusXxx (), minusXxx (): modification date and time, to re-modified to receive the new object

isLeapYear (): determine whether it is a leap year

2, phase date or time: Date Period interval and duration Duration

between (x, y): two date or time

3, Format: DateTimeFormatter

Use predefined pattern: ISO_LOCAL_DATE

Use custom mode: e.g. yyyy-MM-dd HH: mm: ss

Use FormatStyle enumeration constants: LONG, MEDIUM, SHORT

And system-related classes

1, java.lang.System categories: System Tools

 

 

static long currentTimeMillis (): Get the value of the system time in milliseconds

 

static void exit (x): Exit JVM

 

static void arraycopy (subscript starting source array, the starting index of the original array, an array of targets, the target array, a total of several elements copy)

 

static void gc (): inform the garbage collector work

 

static String getProperty (system property name)

 

2, java.lang.Runtime categories: JVM runtime environment

static Runtime getRutime()

long totalMemory()

long freeMemory()

void gc()

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/Objecting/p/12233478.html