Append element to one of the Java array dimension arrays

Source: Internet
Author: User

http://www.verejava.com/?id=16992650730025

/*数组分类1. 一维数组    1.1 一维数组的定义和初始化    1.2 对一维数组的操作, 遍历,添加,插入,修改,删除,排序,查找2. 二维数组    2.1 二维数组的定义和初始化    2.2 二维数组的遍历3. 多维数组4. 增强for循环*/public class ArrayAppend{    public static void main(String[] args)    {        //一维数组的定义和初始化        //静态定义一维数组        int[] scores={90,70,50,80,60,85};                        //向一维数组scores末尾中添加一个学生的成绩 75.        /*        思路:            1. 先创建一个比原来scores数组长度大1的临时数组 tempArray            2. 将scores数组的每一个值复制到 tempArray            3. 然后将 成绩为 75 赋值到 tempArray的新增最后的索引位置            4. 最后将tempArray地址指针引用赋值给 scores;        */        int[] tempArray=new int[scores.length+1];        for(int i=0;i<scores.length;i++)        {            tempArray[i]=scores[i];        }        tempArray[scores.length]=75;        scores=tempArray;        //打印输出添加75成绩后的scores        for(int i=0;i<scores.length;i++)        {            System.out.print(scores[i]+",");        }    }}

http://www.verejava.com/?id=16992650730025

Append element to one of the Java array dimension arrays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.