Set Interface. Flashcards
1
Q
- Does set contains insertion order and duplicate?
- What are all the Set interface?
- wt is the ds of set I ?
- If you want sorting in Set what will you do?
- Wt are the sub Interface we have in Set?
- Does linkedhash set follow insertion order?
A
- Duplicates not allowed and insertion order also not allowed.
- Hashset and Linked hashset
- Linked List is the DS
- I can use Sorted set (sub interface). for this
- We have Sorted set , navigable set , tree set .
2
Q
- How to convert linkedlist to linked hashset?
- Very Important , how do you convert a collection into Array?
- Very Important. if we convert toarray() incase if we have string value to in linked list what will happen ?
- What happen if we give
ll.add(sd);
Here, sd is a object name.
A
- Create linkedhashset object and pass the reference name in the print (parameters).
- By giving toarray();, but map can’t change
- It won’t print to make it print all obejcts we need to give
Object ob = ll.toarray().
Note: Because, why we giving object because Array accepts only homogenous objects .
and object is parent of all the String [] , char[] , int[] , and we can create our own array too like Laptop [] .
4. sd is a object name so it will print output as hashcode
To print a string , we need to give public void toString() method and give return “ABC”; Now it will print ABCas output.
3
Q
- What is the use of toString() method?
A
1.The toString method is used to return a string representation of an object. If any object is printed, the toString() method is internally invoked by the java compiler.
4
Q
Tree Set
A