将10名学生添加到Arraylist中 [英] Add 10 student into Arraylist

查看:71
本文介绍了将10名学生添加到Arraylist中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我正在尝试将10个学生班级的学生添加到arraylist中,这是我在Section Class中构建的,但是我没有做到这一点,所以我需要对我的问题提出一些建议,这是我在section中使用的代码,然后在该代码中执行主要:

Hello.
I am trying to add 10 student of class Student into arraylist which i built it in Section Class but i failed to do this so i need some suggestions to my problem this is the code i used in section and followed by the code will be executed in the main :

ArrayList<string> section = new ArrayList<string>();</string></string>





public ArrayList<string> getStudent() {
			return section;

	}

	public void setStudent(String student) {
		section.add(student);
	}</string>


public static void main(String[] args) throws Throwable {
		Teacher teacher = new Teacher();
		Course course = new Course();
		Section section = new Section();
		Student student = new Student();
		student.setName("Hani");
		student.setName("Salah");
		section.section.add(student.getName());
		student.setName("Amjad");
		System.out.println(section.section.size());
		section.setStudent(student.getName());
		System.out.println(section.getStudent());

	}

推荐答案

只需执行以下操作:

Just do this:

ArrayList<string> section = new ArrayList<string>();

section.add("name1");
section.add("name2");
section.add("name3");
...
section.add("name10");



0)为什么要使用一种方法来做一些简单的事情,就像将学生姓名添加到arraylist一样?

1)我不明白您为什么要呼叫section.section.add.这甚至不应该编译(当然,Java是它自己的动物,我也不写Java代码).

2)考虑使用任何可用的调试器.与您键入此问题并等待答复的时间相比,它可以在更短的时间内显示出您所有的错误.



0) Why are you using a method to do something as simple as adding a student name to the arraylist?

1) I don''t understand why you''re calling section.section.add. This shouldn''t even compile (of course, Java is its own animal, and i don''t write java code).

2) Consider using whatever debugger is available to you. It will reveal ALL of your mistakes in less time than it took you to type this question and wait for a response.


这篇关于将10名学生添加到Arraylist中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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