简体   繁体   English

控制台不打印任何东西

[英]Console not printing anything

It is not printing anything there is no error.它没有打印任何东西,没有错误。 kindly help me in resolving his error.请帮助我解决他的错误。 I have tried three methods to print but still not a single one is working and there isn't any error.我已经尝试了三种打印方法,但仍然没有一种可以工作,也没有任何错误。

import java.util.ArrayList;

public class JavaEight {

    public static void main(String args[])
    {
        ArrayList<Employee> Emp = new ArrayList<>();
        Employee e1 = new Employee(101, "Ravi", "Delhi", "2000");
        Employee e2 = new Employee(102, "Vineet", "Mangalore", "5000");
        Employee e3 = new Employee(103, "Punit", "Mumbai", "3000");
        Employee e4 = new Employee(104, "Shruti", "Banglore", "6000");
        Employee e5 = new Employee(105, "Ritu", "Hyderabad", "8000");
        
        for(int i=0; i<Emp.size();i++)
        {   
            Employee e = (Employee)Emp.get(i);
            System.out.println(e);
            
        }
        Emp.forEach(i -> System.out.println(Emp));
        
        for(Employee i : Emp)
        {
            System.out.println(Emp);
        }
        
        
    }
    }

emp.add(e1); emp.add(e1); etc is missing等丢失

you have created the employee objects, but you did not add them to the list.您已经创建了员工对象,但没有将它们添加到列表中。 thus the list is blank, and not printing anything因此列表是空白的,并且不打印任何内容

add Employee in your ArrayList.在您的 ArrayList 中添加 Employee。

     ArrayList<Employee> Emp = new ArrayList<>();
        Employee e1 = new Employee(101, "Ravi", "Delhi", "2000");
        Employee e2 = new Employee(102, "Vineet", "Mangalore", "5000");
        Employee e3 = new Employee(103, "Punit", "Mumbai", "3000");
        Employee e4 = new Employee(104, "Shruti", "Banglore", "6000");
        Employee e5 = new Employee(105, "Ritu", "Hyderabad", "8000");
        Emp.add(e1);
        Emp.add(e2);
        Emp.add(e3);
        Emp.add(e4);
        Emp.add(e5);

hope , it will resolve your issue.希望,它会解决您的问题。

This is because your ArrayList Emp is empty.这是因为您的 ArrayList Emp 是空的。 You have created the Employee object but you have not added it to Emp.您已创建 Employee 对象,但尚未将其添加到 Emp。 add it to Emp like Emp.add(e1).像 Emp.add(e1) 一样将它添加到 Emp。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM