如何创建从Java中另一个阵列子阵? [英] How to create a sub array from another array in Java?

查看:89
本文介绍了如何创建从Java中另一个阵列子阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建另一个阵列子阵?是否有开出索引从第一阵列如方法

 方法名(对象数组,诠释开始,诠释完)

我不想去了使循环,使我的计划受到影响。

我不断收到错误:


  

找不到符号的方法copyOfRange(INT [],INT,INT)


这是我的code:

 进口的java.util。*;公共类测试
{
    公共静态无效的主要(字串[] ARG)
    {
        INT [] SRC =新INT [] {1,2,3,4,5};
        INT B1 [] = Arrays.copyOfRange(源,0,2);
    }
}


解决方案

在Java 1.6的加入 Arrays.copyOfRange(..)。因此,也许你没有最新的版本。如果这是不可能的升级,看看 System.arraycopy(..)

How to create a sub-array from another array? Is there a method that takes the indexes from the first array such as:

methodName(object array, int start, int end)

I don't want to go over making loops and making my program suffer.

I keep getting error:

cannot find symbol method copyOfRange(int[],int,int)

This is my code:

import java.util.*;

public class testing 
{
    public static void main(String [] arg) 
    {   
        int[] src = new int[] {1, 2, 3, 4, 5}; 
        int b1[] = Arrays.copyOfRange(src, 0, 2);
    }
}

解决方案

Arrays.copyOfRange(..) was added in Java 1.6. So perhaps you don't have the latest version. If it's not possible to upgrade, look at System.arraycopy(..)

这篇关于如何创建从Java中另一个阵列子阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆