Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interview question on core java

 
Bandita Patel
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class Arraylist.java...i want to make my class to behave as Set...then what need to do? What changes i have to do in my class.....
kindly reply..
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make your ArrayList.java implement the Set interface or just extend the HashSet class
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bandita Acharya wrote:then what need to do?

You need to understand the difference between List and Set Abstract Data Structures!
 
Campbell Ritchie
Sheriff
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did they really ask you that question in an interview? Lists and Sets are like bicycles and boats. The interviewer is asking you to ride your bicycle across the lake. Or maybe to sail the boat up the street.
 
Gaurav Raje
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i believe that the interviewer wants to add the condition of uniqueness... So the answer would be
" I will modify (or override if you are making a subclass) the add method of the data structure to add a contains check before adding. If the object is present.. return false and not add... else add
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic