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
@chandrasekharvalisetty16023 жыл бұрын
Correct
@devendrasingraul89053 жыл бұрын
Yes
@amitbm74972 жыл бұрын
Thank you for sharing this.
@ajinkyakottawar95024 жыл бұрын
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... 🙏😇🙏
@RAHULKUMAR-ye7cj8 жыл бұрын
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.
@jajatisahoo38313 ай бұрын
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.
@ravikumarsunkhesvarapu91226 жыл бұрын
the way u teach is awesome
@atiqulny8 жыл бұрын
Very lively, engaging instructor, best in KZbin.
@jeetendrabarnwal5 жыл бұрын
Thanks for these awesome videos... just wanted to add one point - null was allowed in Java 6 ..in Java 7 null is not allowed..
@saradasai76699 жыл бұрын
Thank you Sir. Your explanation is very good ,clear and easily understandable.
@DurgaSoftwareSolutions9 жыл бұрын
Sarada Sai View 42 videos on Collections in Java, kzbin.info/www/bejne/qHqWh55_qahjm6M View 5 videos on JSF, kzbin.info/www/bejne/qHLEYqqtjLGqZ7s View 50 videos on Oracle, kzbin.info/www/bejne/pomYiH2ZqdNmgdk View 35 videos on Hibernate, kzbin.info/www/bejne/iYubkpWHaNugmsU View 115 videos on Data Structures, kzbin.info/www/bejne/pXKkmnWHe7h4n80 View 58 videos on Struts, kzbin.info/www/bejne/pIrUpKGofaymh8k View 74 videos on Spring, kzbin.info/www/bejne/j6HWd4drZdKnntU View 41 videos on CRT, kzbin.info/www/bejne/nHW1n36GrtuFZ5Y View 12 videos on JAVA Reflections API & Annotations kzbin.info/www/bejne/eKmmqGOrid2NiNU View 39 videos on Java Real Time Project Implementation on Spring,Struts & Hibernate, kzbin.info/www/bejne/n3zRk2N3nLCNgJI View other videos on ADV JAVA kzbin.info/www/bejne/bmTNfaSKdsekh7c View 9 videos on ENUM, kzbin.info/www/bejne/imLJfoqtfp53Z6c View 16 videos on Serialization, kzbin.info/www/bejne/mHrdl6Wsmdlqp68
@DurgaSoftwareSolutions9 жыл бұрын
Durga Software Solutions Demo Sessions on youtube, Language Fundamentals(16 Videos)kzbin.info/www/bejne/m4W7lWtvqZ2hnas, Operators & Assignments(7 Videos)kzbin.info/www/bejne/Z3uqgIOeft6bd68, Flow Control(6 Videos)kzbin.info/www/bejne/jmfVhGyseZ5gp68.
@nisargmunjpara54319 жыл бұрын
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..!!!!
@jasonarora89118 жыл бұрын
+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
@Skripturz6 жыл бұрын
Thanks, I was wondering the same thing
@varunsen28025 ай бұрын
I think in Priority Queue also, heterogenous objects are not allowed, beacuse in PQ elements are inserted in a some sorted order.
@DurgaSoftwareSolutions5 ай бұрын
Hello Varun. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@rahulkad53922 жыл бұрын
Good job sir 🥰
@techgyan62334 ай бұрын
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
@DurgaSoftwareSolutions4 ай бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@santoshaakubathini59376 жыл бұрын
Nicely explained.. Awesome..
@dhrub68 жыл бұрын
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)?
@rexsam31344 жыл бұрын
Nice one. You missed mentioning which Java version was used to run the code
@DurgaSoftwareSolutions4 жыл бұрын
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
@surendramishra48136 жыл бұрын
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
@sangeethagopi43622 жыл бұрын
I too have the same doubt... someone please clear our doubt
@senthil781810 жыл бұрын
Durga sir plz upload videos on map collections
@javadsa3678 ай бұрын
Before Java 7, it was possible to add null elements to an empty TreeSet.
@Rohith-ov7vr Жыл бұрын
in priorityque also the hetogeneous data not allowed
@horriblecoder72806 жыл бұрын
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.
@horriblecoder72806 жыл бұрын
null as first element was considered as bug in java 1.6
@jvsnyc4 жыл бұрын
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.
@rohitlovesnature7 жыл бұрын
sir, can you please provide videos on hashmap and map interface
@Modern_revolution5 жыл бұрын
Thank you so much for your help!
@manassahoo2750 Жыл бұрын
Sit please imporve your graphics and light .
@algorithmsguide50765 жыл бұрын
Thankyou sir ji !!
@devendrasingraul89053 жыл бұрын
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
@kamalapuramsivasankar710 ай бұрын
Thanks sir...
@I_am_J300 Жыл бұрын
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
@DurgaSoftwareSolutions Жыл бұрын
Hello Jishan. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@ashishshrivastava45326 жыл бұрын
Null is not allowed in TreeSet But allowed in Hash Set So I request you to correct this one.
@MayurKalambkar Жыл бұрын
in java 1.8 null value is not allowed in TreeSet. So you are showing program of which version.
@DurgaSoftwareSolutions Жыл бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@sohrabalam96502 жыл бұрын
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
@DurgaSoftwareSolutions2 жыл бұрын
Hello Sohrab. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@addicted2headway Жыл бұрын
sir, i am trying to insert null value in empty treeset then also i am getting nullpointer exception
@DurgaSoftwareSolutions Жыл бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@VarunKumar-yy5sr6 жыл бұрын
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.
@ajinzrathod3 жыл бұрын
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.
@DurgaSoftwareSolutions3 жыл бұрын
Hello Ajinkya. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@pranavdeshpande96758 жыл бұрын
sir pls upload videos for Queue nad Map too...
@pal010610 жыл бұрын
what happens if we try to create a tree set with the third constructor using a collection of heterogeneous elements?
@surajmahtosbg5 жыл бұрын
watch full video
@WonderfulSound85 жыл бұрын
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);
@jvsnyc4 жыл бұрын
Read Amiley Jones comment!
@senthil781810 жыл бұрын
This collections videos is enough for collection interview question.?Expecting a reply.Thanks in advance
@DurgaSoftwareSolutions9 жыл бұрын
SENTHIL KUMAR View 9 videos on ENUM, kzbin.info/www/bejne/imLJfoqtfp53Z6c View 16 videos on Serialization, kzbin.info/www/bejne/mHrdl6Wsmdlqp68
@lipikabarman1012 Жыл бұрын
after 1.6 version it not working sir. We are not able to insert null value in TreeSet
@DurgaSoftwareSolutions Жыл бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@Tarun1kumar19899 жыл бұрын
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); } }
@DurgaSoftwareSolutions9 жыл бұрын
+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 KZbin: 1. Language Fundamentals(16 Videos) kzbin.info/www/bejne/m4W7lWtvqZ2hnas 2. Operators &Assignments(7 Videos) kzbin.info/www/bejne/Z3uqgIOeft6bd68 3. Flow Control(6 Videos) kzbin.info/www/bejne/jmfVhGyseZ5gp68 4. Exception Handling (10 Videos) kzbin.info/aero/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
@rickyb89899 жыл бұрын
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)
@CorporateKahani8 жыл бұрын
+ricky b hi ricky, it was possible until 1.6 version only
@aditya12all7 жыл бұрын
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
@parameshyannam85427 жыл бұрын
Sir, why TreeSet and TreeMap Are not allowed Heterogenious Objects ??
@anirbanmajumdar7817 жыл бұрын
Because the underline data structure is Balanced Tree and it implements Set, so you cannot actually have sorting done on Hetrogenous objects.
@RAHULKUMAR-ye7cj8 жыл бұрын
How I know about unicode of a is 97 and unicode value of A is 65. I am confused here.
@iam_hindhu10 жыл бұрын
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 ...
@joerokcz9 жыл бұрын
if i tried to put null after an null insertion,what will happen?
@vishwanathtontanal23658 жыл бұрын
Null value is not allowed in TreeSet. Not even single time.
@ajinzrathod3 жыл бұрын
Allowed till 1.6. Since 1.7, null value is not allowed even for first time.
@nitishkadam93237 жыл бұрын
getting null pointer exception while adding null in empty treeset ?? please explain.. thnks
@NikhilMaguluri7 жыл бұрын
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.
@RoyaLockz7 жыл бұрын
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?
@vineetchaurasia74606 жыл бұрын
Null is not allowed
@srikanthr593510 жыл бұрын
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
@ishansoni98199 жыл бұрын
post ur code?
@srikanthr59359 жыл бұрын
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); } }
@bluesteel1 Жыл бұрын
3:21 null insertions are not allowed this is incorrect
@DurgaSoftwareSolutions Жыл бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@JorgeChavez88 жыл бұрын
Number 6 is wrong, TreeSet doesn't allow you to insert null objects.
@tx302899 жыл бұрын
nice English :)
@DurgaSoftwareSolutions9 жыл бұрын
***** 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)kzbin.info/www/bejne/m4W7lWtvqZ2hnas 2. Operators & Assignments(7 Videos)kzbin.info/www/bejne/Z3uqgIOeft6bd68 3. Flow Control(6 Videos)kzbin.info/www/bejne/jmfVhGyseZ5gp68 durgasoft.com durgasoftonlinetraining.com facebook.com/durgasoftware durgajobs.com facebook.com/durgajobsinfo
@horriblecoder72806 жыл бұрын
his comment was sarcastic.
@vipulgujarathi_73792 жыл бұрын
what is the default size of TreeSet Constructor?
@DurgaSoftwareSolutions2 жыл бұрын
Hello Vipul. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@Mbc43m2767 жыл бұрын
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
@horriblecoder72806 жыл бұрын
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
@HemantShori6 жыл бұрын
you had me at medile
@shilpa364510 жыл бұрын
treeset not allowed null
@DurgaSoftwareSolutions10 жыл бұрын
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.
@Nitinkandwal8 жыл бұрын
null is not allowed in TreeSet.
@pratikbhardwaj38046 жыл бұрын
from 1.7 version
@surendramishra48136 жыл бұрын
Nitin Kandwal first see full video
@farhadbaghirov90755 жыл бұрын
+ 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]
@Vishwasp135 жыл бұрын
@@farhadbaghirov9075 Customising the comparator and removing null doesn't imply null is allowed. The trick is good but might confuse others.