Java muab kev sib piv sib piv uas yuav tsum tau ua los ntawm txhua chav kawm yog tias peb xav siv Arrays lossis Collections sorting txoj kev. Cov kev sib piv sib piv tau sib pivTo(T obj) txoj kev uas yog siv los ntawm kev txheeb xyuas, koj tuaj yeem tshawb xyuas ib qho Wrapper, String lossis Hnub Hnub kom paub meej qhov no.
Yuav ua li cas interface yuav tsum muaj chav kawm siv los siv nrog kev sau sau?
Rau cov khoom kom muaj kev txiav txim zoo lawv yuav tsum ua raws li interface java. lang. Sib piv. Kev sib piv sib piv muaj ib txoj kev piv rau, uas rov qab qhov tsis zoo, 0, qhov zoo yog tias tus nqi tam sim no tsawg dua, sib npaug, lossis ntau dua tus nqi uas peb muab piv nrog, feem.
Puas yog ib qho interface siv los kho qhov kev xaiv?
Ob leeg Sib piv thiab Sib pivtuaj yeem siv rau kev txheeb cais tab sis muaj qee qhov sib txawv ntawm lawv qhov kev siv. Kev sib piv sib piv tuaj yeem siv los muab ib txoj hauv kev ntawm kev txheeb xyuas whereas Comparator interface tuaj yeem siv los muab ntau txoj hauv kev sorting.
Qhov twg hauv qab no yog txheeb xyuas qhov sib cuam tshuam?
Cov chav kawm uas siv qhov SortedSet interface yog TreeSet. TreeSet: TreeSet chav kawm uas yog siv nyob rau hauv lub moj khaum collections yog ib qho kev siv ntawm SortedSet Interface thiab SortedSet txuas ntxiv Teeb Interface. Nws coj zoo li cov txheej txheem yooj yim nrog rau qhov tshwj tsis yog tias nws khaws cov khoom hauv cov ntawv txheeb.
Qhov kev sib txuas twg yog qhov kev sib sau ua ke algorithm ua haujlwm ntawm?
Java Comparator Interface - Ua haujlwm ntawm kev sau. Sib