国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
1. Introduction
2. Detailed explanation of knowledge points
1. Concept
2. Commonly used methods
3. Precautions
4. Arrays class
4.1. Commonly used methods of the Arrays class
Home Java javaTutorial How to use java System class and Arrays class

How to use java System class and Arrays class

May 22, 2023 pm 08:52 PM
java system arrays

1. Introduction

System is a system class. In the java.lang package of JDK, it can be seen that it is also a core language feature of java. The constructor of the System class is decorated with private and is not allowed to be instantiated. Therefore, the methods in the class are also static methods modified by static.

The Arrays class in JAVA is a tool class that implements array operations. It includes a variety of static methods that can implement array sorting and search, array comparison, and adding elements to the array. Functions such as copying and converting arrays to strings. These methods have overloaded methods for all basic types.

2. Detailed explanation of knowledge points

1. Concept

In the API, the introduction of the System class is relatively simple. We give the definition. System represents the system where the program is located and provides Corresponding system attribute information and system operations.

2. Commonly used methods

  • (1) public static void gc(): Used to run the garbage collector in the JVM and complete the memory Cleaning up garbage

  • (2) public static void exit(int status): Used to end the running Java program. Just pass in a number as a parameter. Usually 0 is passed in as normal status, and others are abnormal status

  • (3) public static long currentTimeMillis(): Get the current system time and January 1970 The millisecond difference between 00:00 on 01st

  • (4) public static Properties getProperties(): is used to obtain the specified key (string name) System property information recorded in

Code demonstration:

package com.Test;
import Test2.MyDate;
import java.awt.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Properties;

public class Main {

private final static String name = "磊哥的java歷險(xiǎn)記-@51博客";

/*
*public static void gc() //回收垃圾
*public static void exit(int status) //退出程序,0為正常狀態(tài),其他為異常狀態(tài)
*public static long currentTimeMillis() //獲取當(dāng)前時(shí)間毫秒值
*public static Properties getProperties() //獲取某個(gè)屬性信息
*/
public static void main(String[] args) {
//構(gòu)造方法被私有 不能創(chuàng)建對(duì)象
//System sy = new System();
//public static void exit(int status) //退出程序,0為正常狀態(tài),其他為異常狀態(tài)
// System.out.println("我要退出了!");
// System.exit(0);
// System.out.println("我已經(jīng)退出了!");
//public static long currentTimeMillis() //獲取當(dāng)前時(shí)間毫秒值
long timeMillis = System.currentTimeMillis();
long time = new Date().getTime();
long timeInMillis = Calendar.getInstance().getTimeInMillis();
System.out.println(timeMillis);
for(int i = 0; i < 5; i++) {
System.out.println("i love java");
}
long timeMillis2 = System.currentTimeMillis();
System.out.println(timeMillis2-timeMillis);
//publicstatic Properties getProperties() //獲取某個(gè)屬性信息
Properties properties = System.getProperties();
System.out.println(properties);
System.out.println("============="+name+"=============");
}
}

How to use java System class and Arrays class

3. Precautions

The System class cannot create objects manually because the construction method is privately modified, preventing the outside world from creating objects. All methods in the System class are static and can be accessed by class name. In the JDK, there are many such classes.

4. Arrays class

The Arrays class is a tool class provided by jdk specifically for operating arrays, located in the java.util package.

4.1. Commonly used methods of the Arrays class
  • (1) toString() method of Arrays - returns the string representation of the contents of a specified array..?

  • (2) Arrays copyOf () //Copy the specified array, intercept or fill with null (if necessary), so that the copy has the specified length.?

  • (3) Arrays sort() // Sort the specified type array in ascending numerical order.

  • (4) Arrays binarySearch () //Use binary search method to search the specified type array to obtain the specified value //Must be ordered

  • (5)Arrays fill() //Assign the specified type value to each element in the specified range of the specified type array

  • If two arrays of a given type mutually If equal, return true.

Code Demo:

package com.Test;
import java.util.Arrays;
/* Arrays toString () //返回指定數(shù)組內(nèi)容的字符串表示形式。
Arrays copyOf () //復(fù)制指定的數(shù)組,截取或用 null 填充(如有必要),以使副本具有指定的長(zhǎng)度。
Arrays sort() //對(duì)指定的類(lèi)型數(shù)組按數(shù)字升序進(jìn)行排序。
Arrays binarySearch () //使用二分搜索法來(lái)搜索制定類(lèi)型數(shù)組,以獲得指定的值 //必須有序
Arrays fill() //將指定的類(lèi)型值分配給指定 類(lèi) 型數(shù)組指定范圍中的每個(gè)元素
Arrays equals() //如果兩個(gè)指定的類(lèi)型數(shù)組彼此相等,則返回 true。*/
public class Test{
private final static String name = "磊哥的java歷險(xiǎn)記-@51博客";
public static void main(String args[]){

//定義數(shù)組
int[] score={1,2,3};
int[] scores={1,2,3};
//數(shù)組之間比較,長(zhǎng)度,值相等,則認(rèn)為兩個(gè)數(shù)組相等,返回布爾值
System.out.println("比較值和長(zhǎng)度:"+Arrays.equals(score,scores));
//判斷地址
if(score==scores){
System.out.println("score和scores比較,相等");
}else{
System.out.println("score和scores比較,不相等");
}
//定義二維數(shù)組
int[][] sc={{222,333,1,2,0},{1,2,3,2,0}};
//排序
Arrays.sort(sc[1]);
System.out.println("排序:"+Arrays.toString(sc[1]));
System.out.println("按照下標(biāo)取值:"+sc[0][1]+" ");

//定義數(shù)據(jù)se
int[] se={1,2,3,4,5};
//填充數(shù)組
Arrays.fill(se,0);
System.out.println("填充:"+Arrays.toString(se));
//復(fù)制值到sx,增加指定長(zhǎng)度
int[] sx=Arrays.copyOf(se,2);
//輸出sx的填充后的值
System.out.println("復(fù)制2:"+Arrays.toString(sx));
int[] xb={14,20,67,34,33,23,10};
//排序xb
Arrays.sort(xb);
System.out.println(Arrays.toString(xb));
//在排序后,通過(guò)二分查找,找到34的元素,并返回下標(biāo)
int index1=Arrays.binarySearch(xb,34);
System.out.println("二分法取值:"+index1);
System.out.println("============="+name+"=============");
}
}

How to use java System class and Arrays class

How to use java System class and Arrays class

##4.2. Refinement Exercise
In using the Arrays class, we will use some basic algorithms such as sorting, etc.

Title:

  • (1) Create an int type array A, the value of A is {1,2,3,4,5}

  • (2) Copy the value of A into B with a length of 6

  • (3) Compare whether A and B are the same

Experimental steps:

  • (1) Declare a class Test and create two arrays

  • (2) Use Arrays related methods to complete the operation

Code demonstration:

package com.Test;

import java.util.Arrays;
/*聲明一個(gè)類(lèi)Test,并且創(chuàng)建兩個(gè)數(shù)組*/
/* Arrays toString () //返回指定數(shù)組內(nèi)容的字符串表示形式。
Arrays copyOf () //復(fù)制指定的數(shù)組,截取或用 null 填充(如有必要),以使副本具有指定的長(zhǎng)度。
Arrays sort() //對(duì)指定的類(lèi)型數(shù)組按數(shù)字升序進(jìn)行排序。
Arrays binarySearch () //使用二分搜索法來(lái)搜索制定類(lèi)型數(shù)組,以獲得指定的值 //必須有序
Arrays fill() //將指定的類(lèi)型值分配給指定 類(lèi) 型數(shù)組指定范圍中的每個(gè)元素
Arrays equals() //如果兩個(gè)指定的類(lèi)型數(shù)組彼此相等,則返回 true。*/
public class Main {
private final static String name = "磊哥的java歷險(xiǎn)記-@51博客";
public static void main(String[] args){
//創(chuàng)建int類(lèi)型數(shù)組A,A的值為{1,2,3,4,5}
int[]A = new int[]{1,2,3,4,5};
//將A的值拷貝進(jìn)長(zhǎng)度為6的B中
int[]B = Arrays.copyOf(A, 6);
//比較A和B是否相同
System.out.println("兩個(gè)數(shù)組是否相等:"+Arrays.equals(A, B));
System.out.println("============="+name+"=============");
}
}

How to use java System class and Arrays class

The above is the detailed content of How to use java System class and Arrays class. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
How to handle transactions in Java with JDBC? How to handle transactions in Java with JDBC? Aug 02, 2025 pm 12:29 PM

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

Understanding the Java Virtual Machine (JVM) Internals Understanding the Java Virtual Machine (JVM) Internals Aug 01, 2025 am 06:31 AM

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa

How to work with Calendar in Java? How to work with Calendar in Java? Aug 02, 2025 am 02:38 AM

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear

Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Aug 04, 2025 pm 12:48 PM

Pre-formanceTartuptimeMoryusage, Quarkusandmicronautleadduetocompile-Timeprocessingandgraalvsupport, Withquarkusoftenperforminglightbetterine ServerLess scenarios.2.Thyvelopecosyste,

Understanding Network Ports and Firewalls Understanding Network Ports and Firewalls Aug 01, 2025 am 06:40 AM

Networkportsandfirewallsworktogethertoenablecommunicationwhileensuringsecurity.1.Networkportsarevirtualendpointsnumbered0–65535,withwell-knownportslike80(HTTP),443(HTTPS),22(SSH),and25(SMTP)identifyingspecificservices.2.PortsoperateoverTCP(reliable,c

How does garbage collection work in Java? How does garbage collection work in Java? Aug 02, 2025 pm 01:55 PM

Java's garbage collection (GC) is a mechanism that automatically manages memory, which reduces the risk of memory leakage by reclaiming unreachable objects. 1.GC judges the accessibility of the object from the root object (such as stack variables, active threads, static fields, etc.), and unreachable objects are marked as garbage. 2. Based on the mark-clearing algorithm, mark all reachable objects and clear unmarked objects. 3. Adopt a generational collection strategy: the new generation (Eden, S0, S1) frequently executes MinorGC; the elderly performs less but takes longer to perform MajorGC; Metaspace stores class metadata. 4. JVM provides a variety of GC devices: SerialGC is suitable for small applications; ParallelGC improves throughput; CMS reduces

Comparing Java Build Tools: Maven vs. Gradle Comparing Java Build Tools: Maven vs. Gradle Aug 03, 2025 pm 01:36 PM

Gradleisthebetterchoiceformostnewprojectsduetoitssuperiorflexibility,performance,andmoderntoolingsupport.1.Gradle’sGroovy/KotlinDSLismoreconciseandexpressivethanMaven’sverboseXML.2.GradleoutperformsMaveninbuildspeedwithincrementalcompilation,buildcac

go by example defer statement explained go by example defer statement explained Aug 02, 2025 am 06:26 AM

defer is used to perform specified operations before the function returns, such as cleaning resources; parameters are evaluated immediately when defer, and the functions are executed in the order of last-in-first-out (LIFO); 1. Multiple defers are executed in reverse order of declarations; 2. Commonly used for secure cleaning such as file closing; 3. The named return value can be modified; 4. It will be executed even if panic occurs, suitable for recovery; 5. Avoid abuse of defer in loops to prevent resource leakage; correct use can improve code security and readability.

See all articles