۳۵٪ تخفیف روی تمامی دوره ها🔥 + دوره زبان تخصصی و مهاجرت با ارزش ۵ میلیون تومان بصورت هدیه
۰ ثانیه
۰ دقیقه
۰ ساعت
۲ اميرحسین رضائی
element ordered
جامعه جاوا (وب و دسکتاپ) ایجاد شده در ۱۹ شهریور ۱۴۰۲

درود بر استاد عزیز، استاد TreeSet و TreeMap داده‌ها را به ترتیب حروف الفبا sort میکنند و نه ترتیبی که ما وارد کردیم پس چرا در ستون دوم yes شدند؟

سلام امیر حسین جان،

لطفا برام اسکرین شات بفرست از تست و کد یا توی تلگرام یا گروه تلگرام بهم پیام بده تا بهتر متوجه بشم.

سپهر نامدار ۱۹ شهریور ۱۴۰۲، ۰۹:۰۷

Both `TreeSet` and `TreeMap` maintain their elements in sorted order, the insertion order is not preserved. The ordering is determined by the natural ordering of elements or a custom comparator, and it's based on the key values in the case of `TreeMap`.

In other words:

TreeSet: The elements are sorted according to their natural order or a custom comparator. The order is .determined at the time of insertion and is unrelated to the order in which elements were added

TreeMap: The order is based on the keys. The keys are sorted either according to their natural order or a custom comparator. Again, the order is determined at the time of insertion and is not related to the order in which entries were added.

If you need to preserve the order in which elements were inserted, you might want to consider using other collection types like `LinkedHashSet` or `LinkedHashMap`. These collections maintain the order of 

insertion, providing a predictable iteration order.

Merci ChatGPT

Shahin Bavili ۲۲ آذر ۱۴۰۲، ۰۸:۵۷