Well explained! Durga is a great teacher . As this video is 4 years old , i would like to mention here that till java 1.6 null was allowed in TreeSet but it was considered as bug and in java 7 null is not allowed now in TreeSet. From the documentation of TreeSet: NullPointerException - if the specified element is null and this set uses natural ordering, or its comparator does not permit null elements
Don't have words to say thank you for Durga sir...😊 They teach us from very basic concepts and in very easy words with live examples, this way it help me to remember in easy way... Keep going sir...😊 Lot's of love to you and your family... ❤️ God bless you Sir... 🙏😇🙏
Durga sir is a very good teacher. In my whole life, i never meet with such type of sir who taught very well. Lots of confusion in java, but now my all dout is cleared. Thanku so much sir. Is there any video for android except sandeep sir. Please help me.
For an empty tree-set, when trying to insert null as the first value, one will get NPE from JDK 7. From JDK 7 onwards, null is not at all accepted by TreeSet. However, up to JDK 6, null was accepted as the first value, but any insertion of more null values in the TreeSet resulted in NullPointerException. Hence, it was considered a bug and thus removed in JDK 7.
Sarada Sai View 42 videos on Collections in Java, ruclips.net/video/rI3VkItC0eA/видео.html View 5 videos on JSF, ruclips.net/video/rAa1wwWLw1Y/видео.html View 50 videos on Oracle, ruclips.net/video/pX5WJctn3Kw/видео.html View 35 videos on Hibernate, ruclips.net/video/SZ8abQ3vmdc/видео.html View 115 videos on Data Structures, ruclips.net/video/oAAiBQFSEik/видео.html View 58 videos on Struts, ruclips.net/video/nYqsnrHGsQg/видео.html View 74 videos on Spring, ruclips.net/video/YpsFT50mths/видео.html View 41 videos on CRT, ruclips.net/video/fDRnKPyvR14/видео.html View 12 videos on JAVA Reflections API & Annotations ruclips.net/video/BxCw0uTxZRs/видео.html View 39 videos on Java Real Time Project Implementation on Spring,Struts & Hibernate, ruclips.net/video/iKnb0AgKZJ0/видео.html View other videos on ADV JAVA ruclips.net/video/83jLqTAbqQU/видео.html View 9 videos on ENUM, ruclips.net/video/T1fMWwI9D1E/видео.html View 16 videos on Serialization, ruclips.net/video/bIzfrvdt7qM/видео.html
Hello sir these are incredible stuff we are having. Thank you for it. I have question regarding constructors of "TreeSet(Collection c)." In treeset heterogenous objects are not allowed and what if we create/convert ArrayList collection "c"(or any collection object which consists heterogenous objects) into a TreeSet object with " new TreeSet(Collection c) " constructor???? Hows it possible? Thank you..!!!!
+Nisarg Munjpara There is no way if there are heterogenous elements.You will get exception.You have to remove heterogenous elements and then you can take advantage of TreeSet(Having duplicate removed + Sorting elements) but no order preserved
One thing I am not able to understand please correct me if I am wrong, when 4. TreeSet t = new TreeSet(Collection c); is there then why we need 3. TreeSet t = new TreeSet(SortedSet s); even though SortedSet also a Collection
Hello Seetesh. Thanks for your valuable feedback. It will boost us to do new things. Please subscribe to get updates about new videos. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
Might be some changes in new java version that's why Null not support import java.util.TreeSet; public class InterfacePractice { public static void main(String[] args) { TreeSet treeSet = new TreeSet(); treeSet.add(null); System.out.println(treeSet); } } Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.compareTo(Object)" because "k1" is null
If you look at the internal implementation of the TreeSet, it uses natural ordering, that means TreeSet uses Comparable interface by default to sort its value by comparing other value. Just think programmatically, how will you compare the null value to other. Is it make sense to compare the value with other(NULL) which doesn't have any value in it. That's why java developer made it TreeSet such a way that, it will throw NullPointerExeption when you try to store null value.
I believe that nulls are the second worst problem in all of computer science and programming. Inconsistent handling of them, i.e. are two nulls equal or not, etc. is the first.
Hi Sir, I am your student. I got a job after clearing my doubts in Collections and Threads. Thanks a lot. I have a Question. How will we break TreeSet property (it should store Objects in non sorted order)?
sir i tried to add thiss......t.add(null) for empty set obj still getting exception.. Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.compareTo(Object)" because "k1" is null
But in my JDK-8, I am adding null in empty TreeSet and getting NullPointerException. E.g. import java.util.TreeSet; public class TreeSetDemo { public static void main(String[] args) { TreeSet treeSet = new TreeSet(); treeSet.add(null); } } Result : Exception in thread "main" java.lang.NullPointerException
Hi Sir, I have added only null value then also i am getting null pointer exception. import java.util.*; class TreeSetDemo1 { public static void main(String[] args) { TreeSet t=new TreeSet(); t.add(null); System.out.println(t); } }
+Tarun Kumar Hello, We are very Happy to say Now you can access All DURGA Sir's Core Java with OCJP/SCJP Video Sessions. To get Maximum Benefit from these video sessions, compulsory you have to write notes also. Sir will dictate each and every point clearly. Demo Sessions on RUclips: 1. Language Fundamentals(16 Videos) ruclips.net/video/eTXd89t8ngI/видео.html 2. Operators &Assignments(7 Videos) ruclips.net/video/1JGOPhIyhAM/видео.html 3. Flow Control(6 Videos) ruclips.net/video/X6rS9vD9-qM/видео.html 4. Exception Handling (10 Videos) ruclips.net/p/PLd3UqWTnYXOnSkaum39zWYI6bPb3i7liz Please give your valuable feedback and it is very important and helpful for us. Note:-If you are interested for full version of videos please revert back for more information. Fee : 6000/- Duration: 6-months DURGASOFT Online Training Team, Mobile : +91-7207 21 24 28 +91-8885 25 26 27 Mail ID : durgasoftonline@gmail.com , durgasoftonlinetraining@gmail.com
It says in the compatibility notes from Java 6 to Java 7 that the possibility of adding null to a TreeMap was a bug: oracle.com/technetwork/java/javase/…. See also: bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147
As per explaination, heterogeneous objects are not allowed but also u said default sorting order for numbers is assessing and characters is alphabetical order. If it is the case y can't we insert heterogeneous elements like alphabets as some elements and numbers as some other elements. Because as per explaination numbers should sort in assending order and characters in alphabetical order. Please clarify.
Allowing Null within a collection of unique values is generally considered bad practice and disallowed in a lot of implementations with a similar mentality. Could you describe a situation where you'd need to insert Null into a Set that it'd be beneficial and improve the overall code quality?
Hello sir, i am trying to insert null in an empty treeset but still i am getting null pointer exception does treeset really allows null acceptance for once
Ishan Soni package name; import java.util.Comparator; import java.util.HashSet; import java.util.TreeSet; public class treeset { public static void main(String []args) {
sir , i trying this program ( am using java 1.7) i have an doubt on Null Acceptance .... TreeSet treeSet=new TreeSet(); treeSet.add(null); System.out.println(" tree Set is : "+treeSet); if i want execute this program i got an Runtime Exception like : Exception in thread "main" java.lang.NullPointerException at java.util.TreeMap.compare(Unknown Source) at java.util.TreeMap.put(Unknown Source) at java.util.TreeSet.add(Unknown Source) at com.practice.collections.TreeSetExample.main(TreeSetExample.java:10) but in your sample example you didn't get any exception ... i got confused which one is correct Sir, You said TreeSet accepted null (for only one time) but in program i got error like what am mention above .... please clarify my doubt ...
I'm adding null as my first element, but I'm getting NPE))) Here's my code)) TreeSet treeSet = new TreeSet(); treeSet.add(null); System.out.println(treeSet);
***** Hi, We are very Happy to say Our Expert Faculty Durga Sir's One-to-One Video Sessions on "Core Java with SCJP/OCJP" are available. Shooted from direct Class Room. YOu can access these videos from anywhere anytime. Around 200+ hours training, 178 Videos with clear explanation on every concept. 100% Satisfaction and Perfection in Subject guaranteed. For Demo Sessions Please call or drop a mail to us... DURGASOFT Online Training ph: 91-8885252627 mail :durgasoftonline@gmail.com, durgasoftonlinetraining@gmail.com Demo Sessions on youtube: 1. Language Fundamentals(16 Videos)ruclips.net/video/eTXd89t8ngI/видео.html 2. Operators & Assignments(7 Videos)ruclips.net/video/1JGOPhIyhAM/видео.html 3. Flow Control(6 Videos)ruclips.net/video/X6rS9vD9-qM/видео.html durgasoft.com durgasoftonlinetraining.com facebook.com/durgasoftware durgajobs.com facebook.com/durgajobsinfo
Why are there two separate constructors for creating an equivalent collection c and a sortedSet s? I.e TreeSet t =new TreeSet(Collection c) and TreeSet t =new TreeSet(SortedSet s). ? sorted set comes under the collection interface right? Someone please help
In first type of constructor the element order will be naturally sorted. In second type the element order will depend on the customized sorting order that already may have been used. suppose: contents of List x: 5,3,9,7 TreeSet t=new TreeSet(x); contents of TreeSet t:3,5,7,9 suppose: contents of TreeSet x:5,3,9,7 (custmizing in order is done under compare method) TreeSet t=new TreeSet(x); contents of TreeSet t:5,3,9,7 Hence order also moves. For more info read documentation docs.oracle.com/javase/8/docs/api/java/util/TreeSet.html
Yah Shilpa until 1.6 version we can add null to the TreeSet. But from 1.7 version onwards we cannot add null to the TreeSet.This is a small difference wrt versions.
Well explained! Durga is a great teacher . As this video is 4 years old , i would like to mention here that till java 1.6 null was allowed in TreeSet but it was considered as bug and in java 7 null is not allowed now in TreeSet. From the documentation of TreeSet: NullPointerException - if the specified element is null and this set uses natural ordering, or its comparator does not permit null elements
Correct
Yes
Thank you for sharing this.
Don't have words to say thank you for Durga sir...😊
They teach us from very basic concepts and in very easy words with live examples, this way it help me to remember in easy way...
Keep going sir...😊
Lot's of love to you and your family... ❤️
God bless you Sir... 🙏😇🙏
Durga sir is a very good teacher. In my whole life, i never meet with such type of sir who taught very well. Lots of confusion in java, but now my all dout is cleared. Thanku so much sir. Is there any video for android except sandeep sir. Please help me.
Very lively, engaging instructor, best in RUclips.
the way u teach is awesome
For an empty tree-set, when trying to insert null as the first value, one will get NPE from JDK 7. From JDK 7 onwards, null is not at all accepted by TreeSet. However, up to JDK 6, null was accepted as the first value, but any insertion of more null values in the TreeSet resulted in NullPointerException. Hence, it was considered a bug and thus removed in JDK 7.
Good job sir 🥰
Thank you Sir. Your explanation is very good ,clear and easily understandable.
Sarada Sai
View 42 videos on Collections in Java,
ruclips.net/video/rI3VkItC0eA/видео.html
View 5 videos on JSF,
ruclips.net/video/rAa1wwWLw1Y/видео.html
View 50 videos on Oracle,
ruclips.net/video/pX5WJctn3Kw/видео.html
View 35 videos on Hibernate,
ruclips.net/video/SZ8abQ3vmdc/видео.html
View 115 videos on Data Structures,
ruclips.net/video/oAAiBQFSEik/видео.html
View 58 videos on Struts,
ruclips.net/video/nYqsnrHGsQg/видео.html
View 74 videos on Spring,
ruclips.net/video/YpsFT50mths/видео.html
View 41 videos on CRT,
ruclips.net/video/fDRnKPyvR14/видео.html
View 12 videos on JAVA Reflections API & Annotations
ruclips.net/video/BxCw0uTxZRs/видео.html
View 39 videos on Java Real Time Project Implementation on Spring,Struts & Hibernate,
ruclips.net/video/iKnb0AgKZJ0/видео.html
View other videos on ADV JAVA
ruclips.net/video/83jLqTAbqQU/видео.html
View 9 videos on ENUM,
ruclips.net/video/T1fMWwI9D1E/видео.html
View 16 videos on Serialization,
ruclips.net/video/bIzfrvdt7qM/видео.html
Durga Software Solutions
Demo Sessions on youtube,
Language Fundamentals(16 Videos)ruclips.net/video/eTXd89t8ngI/видео.html,
Operators & Assignments(7 Videos)ruclips.net/video/1JGOPhIyhAM/видео.html,
Flow Control(6 Videos)ruclips.net/video/X6rS9vD9-qM/видео.html.
Nicely explained.. Awesome..
Thanks for these awesome videos... just wanted to add one point - null was allowed in Java 6 ..in Java 7 null is not allowed..
Thank you so much for your help!
Hello sir these are incredible stuff we are having. Thank you for it.
I have question regarding constructors of "TreeSet(Collection c)." In treeset heterogenous objects are not allowed and what if we create/convert ArrayList collection "c"(or any collection object which consists heterogenous objects) into a TreeSet object with " new TreeSet(Collection c) " constructor???? Hows it possible?
Thank you..!!!!
+Nisarg Munjpara There is no way if there are heterogenous elements.You will get exception.You have to remove heterogenous elements and then you can take advantage of TreeSet(Having duplicate removed + Sorting elements) but no order preserved
Thanks, I was wondering the same thing
I think in Priority Queue also, heterogenous objects are not allowed, beacuse in PQ elements are inserted in a some sorted order.
Hello Varun.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
One thing I am not able to understand please correct me if I am wrong, when 4. TreeSet t = new TreeSet(Collection c); is there then why we need 3. TreeSet t = new TreeSet(SortedSet s); even though SortedSet also a Collection
I too have the same doubt... someone please clear our doubt
Thankyou sir ji !!
Thanks sir...
Nice one. You missed mentioning which Java version was used to run the code
Hello Seetesh.
Thanks for your valuable feedback. It will boost us to do new things. Please subscribe to get updates about new videos.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
Durga sir plz upload videos on map collections
Might be some changes in new java version that's why Null not support
import java.util.TreeSet;
public class InterfacePractice {
public static void main(String[] args) {
TreeSet treeSet = new TreeSet();
treeSet.add(null);
System.out.println(treeSet);
}
}
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.compareTo(Object)" because "k1" is null
Hello Friend.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
in priorityque also the hetogeneous data not allowed
Before Java 7, it was possible to add null elements to an empty TreeSet.
sir, can you please provide videos on hashmap and map interface
If you look at the internal implementation of the TreeSet, it uses natural ordering, that means TreeSet uses Comparable interface by default to sort its value by comparing other value.
Just think programmatically, how will you compare the null value to other. Is it make sense to compare the value with other(NULL) which doesn't have any value in it. That's why java developer made it TreeSet such a way that, it will throw NullPointerExeption when you try to store null value.
null as first element was considered as bug in java 1.6
I believe that nulls are the second worst problem in all of computer science and programming. Inconsistent handling of them, i.e. are two nulls equal or not, etc. is the first.
Hi Sir,
I am your student. I got a job after clearing my doubts in Collections and Threads.
Thanks a lot.
I have a Question.
How will we break TreeSet property (it should store Objects in non sorted order)?
sir i tried to add thiss......t.add(null) for empty set obj still getting exception..
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.compareTo(Object)" because "k1" is null
Hello Jishan.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
sir, i am trying to insert null value in empty treeset then also i am getting nullpointer exception
Hello Friend.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
But in my JDK-8, I am adding null in empty TreeSet and getting NullPointerException.
E.g.
import java.util.TreeSet;
public class TreeSetDemo {
public static void main(String[] args) {
TreeSet treeSet = new TreeSet();
treeSet.add(null);
}
}
Result : Exception in thread "main" java.lang.NullPointerException
Hello Sohrab.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
watch full video
Hi Sir,
I have added only null value then also i am getting null pointer exception.
import java.util.*;
class TreeSetDemo1
{
public static void main(String[] args)
{
TreeSet t=new TreeSet();
t.add(null);
System.out.println(t);
}
}
+Tarun Kumar
Hello,
We are very Happy to say Now you can access All DURGA Sir's Core Java with
OCJP/SCJP Video Sessions. To get Maximum Benefit from these video sessions,
compulsory you have to write notes also. Sir will dictate each and every point
clearly.
Demo Sessions on RUclips:
1. Language Fundamentals(16 Videos) ruclips.net/video/eTXd89t8ngI/видео.html
2. Operators &Assignments(7 Videos) ruclips.net/video/1JGOPhIyhAM/видео.html
3. Flow Control(6 Videos) ruclips.net/video/X6rS9vD9-qM/видео.html
4. Exception Handling
(10 Videos) ruclips.net/p/PLd3UqWTnYXOnSkaum39zWYI6bPb3i7liz
Please give your valuable feedback and it is very important and helpful
for us.
Note:-If you are interested for full version of videos please revert back for
more information.
Fee
: 6000/-
Duration:
6-months
DURGASOFT Online Training Team,
Mobile : +91-7207 21 24 28
+91-8885 25 26 27
Mail ID : durgasoftonline@gmail.com , durgasoftonlinetraining@gmail.com
Same with me...getting NullPointerException...guess either Durga is wrong or it was previously allow in earlier jdk version(I am using jdk 1.8)
+ricky b hi ricky, it was possible until 1.6 version only
It says in the compatibility notes from Java 6 to Java 7 that the possibility of adding null to a TreeMap was a bug: oracle.com/technetwork/java/javase/…. See also: bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147
As per explaination, heterogeneous objects are not allowed but also u said default sorting order for numbers is assessing and characters is alphabetical order. If it is the case y can't we insert heterogeneous elements like alphabets as some elements and numbers as some other elements. Because as per explaination numbers should sort in assending order and characters in alphabetical order.
Please clarify.
TreeSet t = new TreeSet();
// null is not allow for empty TreeSet
t.add(null);
for Empty TreeSet null is not allow . I am using java 1.8
what happens if we try to create a tree set with the third constructor using a collection of heterogeneous elements?
in java 1.8 null value is not allowed in TreeSet. So you are showing program of which version.
Hello Friend.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
Sit please imporve your graphics and light .
sir pls upload videos for Queue nad Map too...
3:21 null insertions are not allowed this is incorrect
Hello Friend.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
after 1.6 version it not working sir. We are not able to insert null value in TreeSet
Hello Friend.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
Null is not allowed in TreeSet But allowed in Hash Set So I request you to correct this one.
Sir, why TreeSet and TreeMap Are not allowed Heterogenious Objects ??
Because the underline data structure is Balanced Tree and it implements Set, so you cannot actually have sorting done on Hetrogenous objects.
If null value is not working even for first time.
It was allowed till 1.6. Since 1.7, null value is not allowed even for first time.
Hello Ajinkya.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
getting null pointer exception while adding null in empty treeset ??
please explain.. thnks
from java 7 null insertion is not allowed in a treeset. In java 6 it is a bug, that allows null insertion into a empty treeset.
Allowing Null within a collection of unique values is generally considered bad practice and disallowed in a lot of implementations with a similar mentality. Could you describe a situation where you'd need to insert Null into a Set that it'd be beneficial and improve the overall code quality?
This collections videos is enough for collection interview question.?Expecting a reply.Thanks in advance
SENTHIL KUMAR
View 9 videos on ENUM,
ruclips.net/video/T1fMWwI9D1E/видео.html
View 16 videos on Serialization,
ruclips.net/video/bIzfrvdt7qM/видео.html
Hello sir, i am trying to insert null in an empty treeset but still i am getting null pointer exception does treeset really allows null acceptance for once
post ur code?
Ishan Soni
package name;
import java.util.Comparator;
import java.util.HashSet;
import java.util.TreeSet;
public class treeset {
public static void main(String []args) {
TreeSet t1=new TreeSet();
t1.add(null);
System.out.println(t1);
}
}
sir , i trying this program ( am using java 1.7)
i have an doubt on Null Acceptance ....
TreeSet treeSet=new TreeSet();
treeSet.add(null);
System.out.println("
tree Set is : "+treeSet);
if i want execute this program i got an Runtime Exception like :
Exception in thread "main" java.lang.NullPointerException
at java.util.TreeMap.compare(Unknown Source)
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)
at com.practice.collections.TreeSetExample.main(TreeSetExample.java:10)
but in your sample example you didn't get any exception ...
i got confused which one is correct
Sir, You said TreeSet accepted null (for only one time)
but in program i got error like what am mention above ....
please clarify my doubt ...
Null value is not allowed in TreeSet. Not even single time.
Allowed till 1.6. Since 1.7, null value is not allowed even for first time.
if i tried to put null after an null insertion,what will happen?
How I know about unicode of a is 97 and unicode value of A is 65. I am confused here.
Null is not allowed
I'm adding null as my first element, but I'm getting NPE)))
Here's my code))
TreeSet treeSet = new TreeSet();
treeSet.add(null);
System.out.println(treeSet);
Read Amiley Jones comment!
nice English :)
*****
Hi,
We are very Happy to say Our Expert Faculty Durga Sir's One-to-One Video Sessions on "Core Java with SCJP/OCJP"
are available. Shooted from direct Class Room. YOu can access these videos from anywhere anytime. Around 200+ hours
training, 178 Videos with clear explanation on every concept. 100% Satisfaction and Perfection in Subject guaranteed.
For Demo Sessions Please call or drop a mail to us...
DURGASOFT Online Training
ph: 91-8885252627
mail :durgasoftonline@gmail.com, durgasoftonlinetraining@gmail.com
Demo Sessions on youtube:
1. Language Fundamentals(16 Videos)ruclips.net/video/eTXd89t8ngI/видео.html
2. Operators & Assignments(7 Videos)ruclips.net/video/1JGOPhIyhAM/видео.html
3. Flow Control(6 Videos)ruclips.net/video/X6rS9vD9-qM/видео.html
durgasoft.com
durgasoftonlinetraining.com
facebook.com/durgasoftware
durgajobs.com
facebook.com/durgajobsinfo
his comment was sarcastic.
Why are there two separate constructors for creating an equivalent collection c and a sortedSet s?
I.e TreeSet t =new TreeSet(Collection c) and TreeSet t =new TreeSet(SortedSet s). ? sorted set comes under the collection interface right?
Someone please help
In first type of constructor the element order will be naturally sorted.
In second type the element order will depend on the customized sorting order that already may have been used.
suppose:
contents of List x: 5,3,9,7
TreeSet t=new TreeSet(x);
contents of TreeSet t:3,5,7,9
suppose:
contents of TreeSet x:5,3,9,7 (custmizing in order is done under compare method)
TreeSet t=new TreeSet(x);
contents of TreeSet t:5,3,9,7
Hence order also moves.
For more info read documentation
docs.oracle.com/javase/8/docs/api/java/util/TreeSet.html
null is not allowed in TreeSet.
from 1.7 version
Nitin Kandwal
first see full video
+
Kabir Kandwal null is allowed
Let's look at the example shown below:
class data1 {
Integer number;
public data1(Integer number) {
this.number = number;
}
@Override
public String toString() {
return ""+number;
}
}
TreeSet data2set = new TreeSet(new Comparator() {
@Override
public int compare(data1 d1,data1 d2) {
int d1n=d1==null ? 0 : d1.number;
int d2n=d2==null ? 0 : d2.number;
return d1n-d2n;
}
});
data2set.add(null);
data2set.addAll(Arrays.asList(null,null));
System.out.println(data2set);//[null]
@@farhadbaghirov9075 Customising the comparator and removing null doesn't imply null is allowed. The trick is good but might confuse others.
you had me at medile
what is the default size of TreeSet Constructor?
Hello Vipul.
Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
treeset not allowed null
Yah Shilpa until 1.6 version we can add null to the TreeSet. But from 1.7 version onwards we cannot add null to the TreeSet.This is a small difference wrt versions.
Number 6 is wrong, TreeSet doesn't allow you to insert null objects.