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. Excel阅读模式/单元格行列指示/聚光灯开发 技术要点再分享

    1. 引言 文题中所谓技术要点再分享,本意是想在大神Charltsing Liu的博文“简单介绍Excel单元格行列指示的实现原理(俗称聚光灯功能)”的基础上写一点个人开发体会.写本文的初衷有三点,一 ...

  2. python3 使用ssl安全连接发送邮件

    今天在测试,阿里云服务器发邮件时,发现使用默认的25端口,邮件无法正常发送,查了相关的资料,才知道,大部分的云服务器都会禁用25端口,所以才想到使用ssl 发送. 下面为具体的python3 使用ss ...

  3. windows 分页缓冲池 非分页缓冲池

    最近在windows server 2012机器上在做性能测试时,发现8G物理内存,内存使用率占到了90%多,在“进程”列表中所有进程内存相加才2个多G,同时任务管理器->“性能”标签一项中,非 ...

  4. [转帖]Windows 上面IE的历史

    微软向Chrome举手投降 这么多代IE你都用过吗 2019年04月20日 18:48 4030 次阅读 稿源:太平洋电脑网 2 条评论 这个清明假节,很多人过得波澜不惊,然而一个曾被万千网民挂在口中 ...

  5. git常用命令二、:git stash

    Git stash 储藏工作现场(当你不得不新建分支,或者切换分支,但是当前工作区的修改并不想提交) git stash Saved working directory and index state ...

  6. Python——SQL——将查询的数据列表化

    sql = 'select paihao from yang1.cailiaopai' data = datebase.shujuku.sj_select(sql) #将获得的数据进行列表化 data ...

  7. vue cli使用融云实现聊天

    公司有个项目要实现一个聊天功能,需求如下图,略显随意 公司最终选择融云这个吊炸天的即时通信,文档详细的一匹,刚开始看文档感觉很详细实现起来也不麻烦,有很多开源的demo可以在线演示和下载 不过我们的项 ...

  8. audio与video控件/标签的隐藏,iso/Android下自动全屏播放,短暂黑屏问题

    (一)audio音频标签 <audio src="xxx.mp3"></audio> (二)video视频标签 <video src="xx ...

  9. spring-webmvc-DispatcherServlet

    Spring Web MVC is the original web framework built on the Servlet API and has been included in the S ...

  10. [HNOI/AHOI2018]游戏

    题目描述 https://lydsy.com/JudgeOnline/upload/201804/%E6%B9%96%E5%8D%97%E4%BA%8C%E8%AF%95%E8%AF%95%E9%A2 ...