Java ArrayList | User Defined Objects in ArrayList with Example

Поділитися
Вставка
  • Опубліковано 20 січ 2025

КОМЕНТАРІ • 23

  • @jairmartinez6570
    @jairmartinez6570 2 роки тому +3

    This helped me a lot! Thanks for the tutorial

  • @lakshmiprasannat4147
    @lakshmiprasannat4147 Рік тому +1

    Hi ,How to add multiple class objects(like employee, customer) to single list/arraylist

  • @niteshmagar8164
    @niteshmagar8164 2 роки тому

    This is very helpful. please comeup with similar projects using linkedlist and iterator.

  • @alaeddinezaibi4136
    @alaeddinezaibi4136 2 роки тому

    Hello if we want add emplyee by name what we do

  • @samarsingh9096
    @samarsingh9096 Рік тому

    how to return the object when its id is matvhed

  • @bananarang9518
    @bananarang9518 2 роки тому +1

    thank you so much for this

  • @carsncrew4730
    @carsncrew4730 3 роки тому

    how to update on arraylist?

  • @pritiprangyabiswal7627
    @pritiprangyabiswal7627 2 роки тому

    Which app you are writing

  • @lokeshdhakad2563
    @lokeshdhakad2563 3 роки тому

    Can we take details from user

    • @krisbeka7905
      @krisbeka7905 3 роки тому

      import java.util.ArrayList;
      import java.util.List;
      import java.util.Scanner;
      public class Disp {
      private List emplist = new ArrayList();
      // these are methods used for the structure of the arraylist
      private void addemp(Emp employee) {
      emplist.add(employee); // adding the list with employees
      }
      private void removeemp(int age) {
      for (Emp emp : emplist) {
      if (emp.getAge() == age) {
      emplist.remove(emp);
      }
      }
      }
      private void search_emp_byname(String name) {
      for (Emp emp : emplist) {
      if (emp.getName() == name) {
      System.out.println("Info for: " + emp.getName());
      System.out.println("Age: " + emp.getAge());
      System.out.println("Lastname: " + emp.getLastname());
      }
      }
      }
      private void show_emp() {
      for (Emp emp : emplist) {
      System.out.println(emp.getName() + " " + emp.getLastname() + " " + emp.getAge());
      }
      }
      private void clearemp() {
      emplist.clear();
      }
      public static void main(String[] args) {
      Disp disp = new Disp(); // create objects for class Disp
      Scanner sc = new Scanner(System.in);
      boolean flag = true;
      while (flag) {
      System.out.println("Enter 1 if you want to add information , enter 2 if you want to delete information, enter 3 if you want to show the information" + "
      " + " enter 4 if you want to exit or enter 5 if you want to clear all data: ");
      int nr = sc.nextInt();
      switch (nr) {
      case 1:
      System.out.println("How many employees do you want to show: ");
      int e = sc.nextInt();
      for (int i = 0; i < e; i++) {
      System.out.println("Enter name: ");
      sc.nextLine();
      String name = sc.nextLine();
      System.out.println("Enter lastname: ");
      String lastname = sc.nextLine();
      System.out.println("Enter age: ");
      int age = sc.nextInt();
      Emp emp = new Emp(lastname, name, age);
      disp.addemp(emp);
      }
      break;
      case 2:
      System.out.println("Which Employee do you want to delete by age: ");
      int delete = sc.nextInt();
      disp.removeemp(delete); // using the object from class Disp
      System.out.println("Deleted");
      break;
      case 3:
      System.out.println("The Employees are: ");
      disp.show_emp();
      break;
      case 4:
      flag=false;
      System.out.println("You exit");
      break;
      case 5:
      disp.clearemp();
      System.out.println("The register is empty");
      }
      }
      }
      }
      //after you have created the employee class do this class.
      // you can input the values

    • @prasadkadu9737
      @prasadkadu9737  3 роки тому

      Yes , I have made new video, in that we had taken input from user. You can refer that

    • @raihanchowdhury295
      @raihanchowdhury295 2 роки тому

      @@prasadkadu9737 can you please provide the new video link?

    • @prasadkadu9737
      @prasadkadu9737  2 роки тому +1

      @@raihanchowdhury295 ua-cam.com/video/ycrxp5c3OUY/v-deo.html
      There was issue with mic so volume is low

  • @NarenkumarMoorthyVisalatchi

    Solution: for (Iterator iterator = employeeList.iterator(); iterator.hasNext();){
    Employee employee = iterator.next();
    if (employee.getId()==id){
    iterator.remove();
    }
    }

  • @nprathyusha7876
    @nprathyusha7876 3 роки тому

    Here why using private

  • @muhammadzia1497
    @muhammadzia1497 Рік тому

    Thanks

  • @aboobackerm91
    @aboobackerm91 2 роки тому

    Thank you..

  • @yobro7322
    @yobro7322 Рік тому

    sort kese krenge bhai by name

  • @رياحالهاشمية
    @رياحالهاشمية 2 роки тому

    May allah guide you txs