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. 深度解读Tomcat中的NIO模型(转载)

    转自https://www.jianshu.com/p/76ff17bc6dea 一.I/O复用模型解读 Tomcat的NIO是基于I/O复用来实现的.对这点一定要清楚,不然我们的讨论就不在一个逻辑线 ...

  2. 4月18日 MySQL学习

    正式开始了数据库的学习 昨天下好的MySQL 今天正式开始学习的,介绍了多种数据库软件,当然 学习的这个是开源的 免费的. DBMS(数据库管理系统)这就是我们学习的数据库的软件 数据库分为关系型数据 ...

  3. Spring-webflow基础讲解

    什么是webflow: Spring Web Flow构建于Spring MVC之上,允许实现Web应用程序的“流程”.流程封装了一系列步骤,指导用户执行某些业务任务.它跨越多个HTTP请求,具有状态 ...

  4. tomcat server.xml结构

    所有xml文件使用的文件头 <?xml version='1.0' encoding='utf-8'?> 2 <Server port="8005" shutdo ...

  5. BZOJ 2733 永无乡

    splay启发式合并 启发式合并其实就是把集合数量小的合并到集合数量大的里去. 怎么合并呢,直接一个一个插入就行了.. 用并查集维护连通性,find(i)可以找到所在splay的编号 这题好像还可以合 ...

  6. The Preliminary Contest for ICPC China Nanchang National Invitational I. Max answer (单调栈+线段树)

    题目链接:https://nanti.jisuanke.com/t/38228 题目大意:一个区间的值等于该区间的和乘以区间的最小值.给出一个含有n个数的序列(序列的值有正有负),找到该序列的区间最大 ...

  7. vue-cli 项目踩坑 npm install 时出错

    1.报错如下: 2.此时你执行npm run dev  / npm run build 会报错如下 npm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! v ...

  8. bootstrap: 内联表单;

    <form class="form-inline"> <div class="form-group"> <label for=&q ...

  9. redis3.2.10单实例安装测试

    redis3.2.10单实例安装测试 主要是实际使用环境中使用,为了方便快速部署,特意记录如下: # root用户 yum -y install make gcc-c++ cmake bison-de ...

  10. Vue学习笔记六:v-model 数据双向绑定

    目录 v-model简介和适用范围 新建HTML 所见即所得 v-model模拟简易计算器 v-model简介和适用范围 Vue的一大特点之一就是数据的双向绑定,v-model就是实现这个功能的指令, ...