“This is the 17th day of my participation in the August More Text Challenge.

The System class

The System class is in the java.lang package, so we don’t need package guides to use it.

The System class contains some useful class fields and methods. It cannot be instantiated.

Among the facilities provided by the System class, there are standard input, standard output, and error output streams; Access to externally defined properties and environment variables; Methods for loading files and libraries; There are also practical ways to quickly copy part of an array.

Let’s take a look at the fields of the System class.

Field of the System class

Static PrintStream Err Standard error output stream. Static InputStream in standard InputStream. Static PrintStream out static PrintStream outCopy the code

Common methods of the System class

The only two methods we use in the System class are ArrayCopy () and currentTimeMillis().

currentTimeMillis()

Public static Long currentTimeMillis() Returns the current time in milliseconds.Copy the code

What’s the use of getting milliseconds? This will help us test the efficiency of the program.

Let’s look at an example.

/* Test print 1-9999, the required time. */ long start = System.currentTimeMillis(); for (int i = 0; i <10000 ; i++) { System.out.println(i); } long end = System.currentTimeMillis(); System.out.println(end - start);Copy the code

arraycopy()

Public static void arrayCopy (Object SRC, int srcPos, Object dest, int destPos, int length) ArrayCopy (Object SRC, int srcPos, Object dest, int destPos, int length) Ends at the specified location in the destination array. A subsequence of array components is copied from the source array referenced by SRC to the destination array referenced by dest. The number of the component to be copied is equal to the length parameter. The components in the source array between srcPos and srcPos+ Length-1 are copied to destPos in the destination array to destPos+ Length-1 respectively. Parameter: src-source array. SrcPos - The starting position in the source array. Dest - Destination array. DestPos - The starting position in the destination data. Length - The number of array elements to copy.Copy the code

We’ll also look at an example to see how to use it.

/ * the SRC = {1, 2, 3, 4} copy of the first three elements to dest = {2, 7} * / int [] SRC = {1, 2, 3, 4}; Int [] dest = {2, 7}; System. Arraycopy (SRC, 0, dest, 0, 3); String s = Arrays.toString(dest); System.out.println(s);Copy the code

As you can see, the element in Dest is overwritten instead of inserted in front of it. Note this.

Write in the last

Ok, that’s all we have to say about the System class. Let’s give it a try!

If the above content is not correct, welcome to dig friends to criticize.