Java基础——常用API2

一、System

1.1 计算机中的时间原点

它表示最初的开始时间,是1970年1月1日00.00。

在我们国家,因为时差的原因实际上是:

那么这句话的意思就是,从时间原点开始到现在你执行这个代码一共过了多少毫秒。

java 复制代码
package com.lkbhua.MyApi.System;

public class demo2 {
    public static void main(String[] args){
        // -------------------------------数据源数组------起始索引-----目的地数组------起始索引-------拷贝个数
        // 3、public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length): 数组拷贝
        // 细节:
        // 1、如果数组源和目的数组都是基本数据类型,那么两者的类型一定要保持一致,否则会报错
        int []arr = {1,2,3,4,5,6,7,8,9,10};
        double []arr1 = new int[10];

        System.arraycopy(arr, 0, arr1, 0, arr.length);

        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i] + " ");
        }

        // 2、在拷贝的时候需要考虑数组的长度,如果超过范围也会报错
        int []arr2 = {1,2,3,4,5,6,7,8,9,10};
        int []arr3 = new int[5];

        System.arraycopy(arr2, 0, arr3, 0, arr2.length);

        for (int i = 0; i < arr3.length; i++) {
            System.out.print(arr3[i] + " ");
        }

        // 3、如果数组源和目的数组都是引用数据类型,那么子类类型可以赋值给父类类型
        Student s1 = new Student("张三", 18);
        Student s2 = new Student("李四", 19);
        Student s3 = new Student("王五", 20);

        Student []students = {s1,s2,s3};

        Person []students1 = new Student[3];
        // 4、数组拷贝
        System.arraycopy(students, 0, students1, 0, students.length);
        // 只不过遍历的时候需要强转
        for (int i = 0; i<arr2.length;i++){
            Student stu = (Student)students1[i];
            System.out.println(stu.getName() + " " + stu.getAge());
        }
    }
}

class  Person{
    private String name;
    private int age;

    public Person() {}

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
}

class Student extends Person{

    public Student() {}

    public Student(String name, int age) {
        super(name, age);
    }
}

声明:

以上均来源于B站@ITheima的教学内容!!!

本人跟着视频内容学习,整理知识引用

相关推荐
一点一木10 小时前
🚀 2026 年 6 月 GitHub 十大热门项目排行榜 🔥
人工智能·github
plainGeekDev10 小时前
Gson → kotlinx.serialization
android·java·kotlin
小bo波19 小时前
Java Swing 图形用户界面实验 —— 从算术练习到游戏开发的完整实践
java·课程设计·gui·游戏开发·扫雷·swing
咖啡八杯20 小时前
GoF设计模式——备忘录模式
java·后端·spring·设计模式
OpenTiny社区1 天前
从零开发 AI 聊天页要两周?试试这款 Vue3 垂直对话组件库 TinyRobot,直接开箱即用
前端·vue.js·github
逛逛GitHub1 天前
2 万多 Star!Google 开源了这个神级 GitHub 项目。
github
SamDeepThinking1 天前
裁掉那个差程序员后,给你看团队里高手的代码:这个习惯,希望你有
java·后端·程序员
逛逛GitHub1 天前
免费 Token 烧掉 5 万亿之后,他们出了个一站式创作平台。
github
朕瞧着你甚好1 天前
技术雷达 & Java 集成评估报告 — Apache Tika 3.3.1
java·ai编程