public class DataTypeDefaultValue {
    public static void main(String[] args) {
        // string类型数组的默认值null
        // 对于引用类型的属性的默认值是null,如String类型
        System.out.println("查看String类型中数组的默认值:");
        String[] str = new String[4];
        str[0] = "aa";
        str[1] = "bb";
        str[2] = "cc";
        for (int i = 0; i < 4; i++) {
            System.out.println(str[i]);
        }

        // 对于short,int,long,byte而言,创建数组的默认值是0
        System.out.println("查看int类型数组的默认值:");
        int[] score = new int[4];
        score[0] = 90;
        score[1] = 89;
        score[2] = 34;
        for (int i = 0; i < score.length; i++) {
            System.out.println(score[i]);
        }

        System.out.println("查看short类型数组的默认值:");
        short[] score1 = new short[4];
        score1[0] = 90;
        for (int i = 0; i < score1.length; i++) {
            System.out.println(score1[i]);
        }

        System.out.println("查看long类型数组的默认值:");
        long[] score2 = new long[4];
        score2[0] = 90;
        for (int i = 0; i < score2.length; i++) {
            System.out.println(score2[i]);
        }

        System.out.println("查看byte类型数组的默认值:");
        byte[] score3 = new byte[4];
        score3[0] = 90;
        for (int i = 0; i < score3.length; i++) {
            System.out.println(score3[i]);
        }

        // 对于float double而言,默认值是0.0
        System.out.println("查看float类型数组的默认值:");
        float[] score4 = new float[4];
        score4[0] = 23;
        for (int i = 0; i < score4.length; i++) {
            System.out.println(score4[i]);
        }

        System.out.println("查看double类型数组的默认值:");
        double[] score5 = new double[4];
        score5[0] = 45;
        for (int i = 0; i < score5.length; i++) {
            System.out.println(score5[i]);
        }

        // 对于char类型
        // char类型数组的默认值是空格
        System.out.println("查看char类型数组的默认值:");
        char[] ch = new char[4];
        ch[0] = 'p';
        for (int i = 0; i < ch.length; i++) {
            System.out.println(ch[i]);
        }

        // 对于boolean类型的数组默认值
        // boolean类型数组的默认值是false
        System.out.println("查看boolean数组的默认值:");
        boolean[] b = new boolean[4];
        b[0] = true;
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }

        /// 引用类型数组的默认值是null
        class Person {

        }
        System.out.println("查看引用类型的数组默认值:");
        Person[] p = new Person[4];
        for (int i = 0; i < p.length; i++) {
            System.out.println(p[i]);
        }
    }
}

运行结果:

查看String类型中数组的默认值:
aa
bb
cc
null
查看int类型数组的默认值:
90
89
34
0
查看short类型数组的默认值:
90
0
0
0
查看long类型数组的默认值:
90
0
0
0
查看byte类型数组的默认值:
90
0
0
0
查看float类型数组的默认值:
23.0
0.0
0.0
0.0
查看double类型数组的默认值:
45.0
0.0
0.0
0.0
查看char类型数组的默认值:
p

java各种数据类型的数组元素的默认值的更多相关文章

  1. Java 创建数组的方式, 以及各种类型数组元素的默认值

    ①创建数组的方式3种 ①第1种方法 public class MyTest { public static void main(String[] args){ //method 1 int[] arr ...

  2. C++:map用法及元素的默认值

    C++:map用法 一.map基本用法 键值对 第一个参数为键的类型,第二个参数为值的类型. 源代码 #include <iostream> #include <string> ...

  3. 关于Java读取mysql中date类型字段默认值'0000-00-00'的问题

    今天在做项目过程中,查询一个表中数据时总碰到这个问题:      java.sql.SQLException:Value '0000-00-00' can not be represented as ...

  4. 【转】MySQL datetime数据类型设置当前时间为默认值

    转自http://blog.csdn.net/u014694759/article/details/30295285 方法一: MySQL目前不支持列的Default 为函数的形式,如达到你某列的默认 ...

  5. (转)日期类型的input元素设置默认值为当天

    原文地址 html5的form元素对日期时间有丰富的支持 <input type="date"> <input type="time"> ...

  6. 日期类型的input元素设置默认值为当天

    html文件:<input name="" type="date" value="" id="datePicker" ...

  7. (Java)怎么去掉字符串数组中重复的值?

    String fdbs = "WXB,WXA,FDA,WXB"; String[] str = fdbs.split(","); Set set = new H ...

  8. c#中的数据类型简介(数组)

    c#中的数据类型简介(数组) 数组定义 可以将数组看成相同数据类型的一组或多组数据,包括一维数组,多维数组和交错数组. 数值数组元素的默认值设置为零,而引用元素的默认值设置为 null. 交错数组是指 ...

  9. Java基础知识笔记第二章:基本数据类型与数组

    标识符和关键字 标识符: 1:字母,数字,下划线,美元符号 2.不能以数字开头 3.标识符不能是:true   false   null(尽管true   false   null不是java的关键字 ...

随机推荐

  1. Linux下ansible的group模块

    一.概述 group 模块可以帮助我们管理远程主机上的组. 二.常用参数 name参数:必须参数,用于指定要操作的组名称. state参数:用于指定组的状态,两个值可选,present,absent, ...

  2. react dnd demo

    target import React ,{ Component } from 'react'; import { DropTarget } from 'react-dnd'; import Item ...

  3. plus.webview更新上一个页面的信息

    let currentWebview = plus.webview.currentWebview();       let backWebview = currentWebview.opener(); ...

  4. 修改注册表信息来兼容当前WebBrower程序

    public class WebBrower { /// <summary> /// 修改注册表信息来兼容当前程序 /// /// </summary> public stat ...

  5. 报错utf-8错误

    当python运行总报utf-8错误时, f = open('CI_CUSER_2019040116033031.txt')data_app = pd.read_csv(f)print(data_ap ...

  6. [2019.03.20]Linux Shell 执行传参数和expr

    前不久入职实习生,现在在帮着组里面dalao们跑Case,时不时要上去收一下有木有Dump,每次敲命令太烦人于是逼着自己学写Shell脚本.一开始真的是很痛苦啊,也没能搞到书,只能凭网上半真半假的消息 ...

  7. winform动态生成新窗体并添加控件执行命令

    主要代码 Form nf = new Form(); ; ; nf.Width = _w; nf.Height = _h; //添加textbox TextBox tb = new TextBox() ...

  8. [pip]upgrade outdated pip package on windows / 在windows上更新所有过时的pip包

    首先更新pip自身: python -m pip install -U pip 查询过期包: pip list --outdated --format=columns Package Version ...

  9. [powershell]获取FCID&Port

    Get-InitiatorID Get-InitiatorPort

  10. vue+elementUI+axios实现的全局loading加载动画

    在项目中,很多时候都需要loading加载动画来缓解用户的焦虑等待,比如说,我打开了一个页面,而这个页面有很多接口请求,但浏览器的请求并发数就那么几个,再加上如果网速不行的话,那么这时候,用户很可能就 ...