zoukankan      html  css  js  c++  java
  • Java 数组 使用arraycope复制数组 使用java工具类操作数组 操作二维数组 使用foreach操作数组

    class arraycope
    {
    /**
    目标数组必须有足够的空间来存放拷贝的元素
    定义任意类型的数组元素拷贝操作,能支持任意类型的数组元素拷贝操作
    */
    public static void main(String[] args)
    {

    	int[]  src= new int[]{101,102,103,104,105,106};
    	int[] dest= new int[]{201,202,203,204,205,206,207};
    	//System.arraycopy(源数组,源数组拷贝起始位置,目标数组,拷贝到目标数组的起始位置,拷贝元素个数)
    	System.arraycopy(src,2,dest,1,2);
    	for (int num:dest)
    	{
    		System.out.println(num+" ");
    	}
    
    }
    

    }

    ==============================
    import java.util.Arrays;
    public class arraysdemo
    {
    /**
    目标数组必须有足够的空间来存放拷贝的元素
    定义任意类型的数组元素拷贝操作,能支持任意类型的数组元素拷贝操作
    */
    public static void main(String[] args)
    {

    	int[]  src= new int[]{111,102,103,104,105,106};
    
    	System.out.println(Arrays.toString(src));//
    	Arrays.sort(src);
    	System.out.println(Arrays.toString(src));//
    	System.out.println(Arrays.binarySearch(src,106));//查找数组索引
    }
    

    }

    ===============================

    class doubleArray
    {
    public static void main(String[] args)
    {

    	int[][] arr = new int[][]{
    		{11,22,33},
    		{44,33,224},
    		{222,88}
    	};
    
    	for (int i = 0;i<arr.length;i++ )
    	{
    		//String str = "[";
    		for (int j = 0;j<arr[i].length;j++ )
    		{
    			int num = arr[i][j];
    			System.out.print(num);
    		}
    		System.out.println(arr[i]);
    	}
    }
    

    }

    =============================
    class foreachArray
    {
    public static void main(String[] args)
    {
    int[] nums = new int[]{10,20,30,50,80};

    	for (int index = 0; index <nums.length ;index++ )
    	{
    		System.out.print(nums[index]+" ");
    

    2
    }
    System.out.println("______________");

    	//使用foreach 打印数组
    	/**
    	 适合直接打印数组 。
    	 语法 for (数组元素类型 变量名:传递的数组){}
    	*/
    	for (int arr :nums )
    	{
    		System.out.print(arr+" ");
    	}
    	
    }
    

    }

  • 相关阅读:
    load data to matlab
    Apriori algorithm
    LOGIN Dialogue of Qt
    Methods for outlier detection
    MFC改变对话框背景色
    g++宏扩展
    Some key terms of Data Mining
    Qt QLabel 显示中文
    How To Debug a Pyhon Program
    C++命名规范
  • 原文地址:https://www.cnblogs.com/thttt/p/11638486.html
Copyright © 2011-2022 走看看