如何从数组中删除元素? [英] How to delete element from array?

查看:80
本文介绍了如何从数组中删除元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void deleteLesson(lesson l) {
       int index = isExistLesson(l);
       if (index != -1) {
           lesson[] newL = new lesson[size - 1];
           for (int i = 0; i < index; i++) {
               newL[i] = listLesson[i];
           }
           for (int i = index + 1; i < size - 1; i++) {
               newL[i] = listLesson[i + 1];
           }
           listLesson = newL;
           size--;
       } else {
           System.err.println("Not Exist");
       }
   }

   public int isExistLesson(lesson l) {
       for (int i = 0; i < size; i++) {
           if (listLesson[i].equals(l)) {
               return i;
           }
       }





我尝试了什么:



我试图纠正我的错误但是有一个零点异常错误



What I have tried:

I have tried to correct my mistake but there is a null point exception error

@Override
public String toString() {
    String res = "Student{" + "name=" + name + " Id:" + id + ":Lessons [";
    for (int i = 0; i < number - 1; i++) {
        res += listLesson[i].toString() + ", ";

        res += listLesson[number - 1].toString() + "]}";
        return res;
    }

    return res;
}



这个部分有人可以帮我吗?


in this part can anyone help me please?

推荐答案

你是那个发布有人可以帮我提供建立大学管理系统项目的建议吗? [ ^ ]?如果是,请删除重复的帐户。
Are you the same person who posted Can anyone help me with advice for creating university management system project?[^]? If so please delete the duplicate account.


这篇关于如何从数组中删除元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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