在java中将数组索引0更改为1

在java中将数组索引0更改为1,java,arrays,Java,Arrays,必须从队列中删除索引0。你回答 始终在索引0上找到的对话上。队列中的所有其他调用必须“向前移动”一步,以便索引1现在应该得到索引0,以此类推。尝试过这种方法和其他许多方法,但都没能奏效 public static void answerCall() { for (int i = 0; i < customerList.length-1; i++) { if (customerList[i] != null && customerList[i + 1

必须从队列中删除索引0。你回答 始终在索引0上找到的对话上。队列中的所有其他调用必须“向前移动”一步,以便索引1现在应该得到索引0,以此类推。尝试过这种方法和其他许多方法,但都没能奏效

public static void answerCall() {
    for (int i = 0; i < customerList.length-1; i++) {
        if (customerList[i] != null  && customerList[i + 1] == null) {
            customerList[i] = null;
            counter--;
        } else if (customerList[i] != null && customerList[i + 1] != null) {
            customerList[i] = customerList[i + 1];
            customerList[i + 1] = null;
            counter--;
        }

    }

}
公共静态无效应答调用(){
对于(int i=0;i

}

我相信这样的方法应该有效:

public static void answerCall()
{
    for(int i = 0; i < customerList.Length - 1; i++)
    {
        if(customerList[i+1] != null)
        {
            customerList[i] = customerList[i+1];
        }
    }
    customerList[customerList.Length] = null;
}
公共静态无效应答调用()
{
对于(int i=0;i
它只是在数组中迭代(最后一个值除外), 并将每个值指定给下一个值

另外,我不完全确定您不需要计数器的是什么,int不能为null,它是0,因为它是一种基本类型:

public static void answerCall() {
    for (int i = 0; i < customerList.length-1; i++) 
    {
        if (customerList[i + 1] == 0) {
            customerList[i] = 0;
        } else if (customerList[i + 1] != 0) {
            customerList[i] = customerList[i + 1];
        }
    }
}
公共静态无效应答调用(){
对于(int i=0;i
您的问题很难理解,但这可能会有帮助吗

Public static void answerCall() {
/* 
for loop iterates through list backwards moving elements forward until index 0
*/
    for (int i = 0; i < customerList.length - 1; i++) { 
        if (i != 0) {
            customerList[CustomerList.length - i] = customerList[customerList.length - (i + 1)];
        } else {
            customerList[0] = 0;
        }
   }
}
公共静态无效应答调用(){
/* 
for循环向后遍历列表,向前移动元素,直到索引为0
*/
对于(inti=0;i
这就是为什么你应该使用集合而不是数组。我知道,但我必须使用数组…为什么所有的
if
语句?循环内的唯一语句应该是
customerList[i]=customerList[i+1]语句。然后在循环之后,将最后一个值设置为
null