1.背景
數組是最最基本的數據存儲方式
數據結構從根本來看其實就2中
數組和鏈表
其他都是在這兩種的基礎上擴展出來的
比如:
隊列-數組鏈表都能實現
棧-數組鏈表都能實現
哈希表-數組和隊列實現
樹-鏈表實現
圖-數組實現
基於數組是java中的基礎,很多童鞋都是學習過的,這裏這是簡單的整理一下,讓課程結構完整!
2.代碼
package com.ldp.course.structure.demo01Array; import com.ldp.course.common.MyArrayUtil; import org.junit.Test; import java.util.Arrays; /** * @create 06/29 6:50 * @description <p> * 數據結構與算法之數組 * 課件: * https://www.cnblogs.com/newAndHui/p/16421890.html * * </p> */ public class Test01Array { /** * 一維數組測試 */ @Test public void test01() { int[] array = {4, 5, 6, 8}; // 顯示數組 System.out.println(Arrays.toString(array)); // 之後的課程中會經常用到數組的顯示,封裝一個方法 MyArrayUtil.showArray(array); } /** * 二維數組測試 */ @Test public void test02() { int[][] array = {{4, 5, 6, 8}, {4, 5, 6, 8}, {4, 5, 6, 8}}; // 顯示數組 for (int[] objects : array) { System.out.println(Arrays.toString(objects)); } // 之後的課程中會經常用到數組的顯示,封裝一個方法 MyArrayUtil.showArray(array); } }
3.數組打印
package com.ldp.course.common; import java.util.Arrays; /** * @create 06/29 6:54 * @description */ public class MyArrayUtil { /** * 一維數組顯示 * * @param array 一維數組 */ public static void showArray(int[] array) { System.out.println(Arrays.toString(array)); } /** * 二維數組顯示 * * @param array 二維數組 */ public static void showArray(int[][] array) { for (int[] objects : array) { System.out.println(Arrays.toString(objects)); } } }