• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Create a logic for Object of ArrayList

Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Folks

I Want to build a logic for an Object of ArrayList.

Below i will provide Boilerplate for a program for which i want a logic to implement.

1. In the above program there are 2 domain class Employee, Result
2. In the main program inside TestProgram class i have added 8 Object of Employee inside empList ArrayList.
3. if you run the program the output will be as below
List Size : 8
Name: Tom Emp ID: 1
Name: Tom Emp ID: 2
Name: Tom Emp ID: 3
Name: Tom Emp ID: 4
Name: Tom Emp ID: 6
Name: Jerry Emp ID: 7
Name: Jerry Emp ID: 8
Name: John Emp ID: 9
4. The Output i require is in resList ArrayList is
Name: Tom, From ID: 1, To ID: 4, Count: 4
Name: Tom, From ID: 6, To ID: 6, Count: 1
Name: Jerry, From ID: 7, To ID: 8, Count: 1
Name: John, From ID: 9, To ID: 9, Count: 1
5. The logic to generate the output is
If Name is same &  Emp ID is in sequence then update the To ID, if sequence is break then create a separate entry in resList.

Please help me out to solve the problem

If further clarification required please comment

Thank you in advance

Posts: 74351
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please explain waht you are trying to do, so we can help you do it.
Don't use underscores in variable names. Not emp_name but empName. Actually, if you are inside an Emplyee class, you shoulsn't use emp at all; simply write name. What does emp_add mean? Why is it a String? There is no such thing as an add in real life, so there shoudn't be a field called add.
Why are you using all those setXXX methods? Why are you not initialising those fields in the constructor?
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic