Cov txheej txheem:

Yuav ua li cas koj siv teeb interface hauv Java?
Yuav ua li cas koj siv teeb interface hauv Java?

Video: Yuav ua li cas koj siv teeb interface hauv Java?

Video: Yuav ua li cas koj siv teeb interface hauv Java?
Video: Yuav ua li cas thiaj thov tau daim ntawv tso cai los qhib business nyob rau lub nroog Minneapolis 2024, Kaum ib hlis
Anonim

Teeb tsa hauv Java

  1. Teeb yog ib interface uas extends Collection. Nws yog ib qho kev sau cov khoom uas tsis tau txiav txim nyob rau hauv uas duplicate qhov tseem ceeb khaws tsis tau.
  2. Hauv paus, Teeb yog ua raws los ntawm HashSet , LinkedHashSet lossis TreeSet (tso sawv cev).
  3. Teeb muaj ntau txoj hauv kev ntxiv, tshem tawm kom meej, loj, thiab lwm yam los txhim kho kev siv ntawm qhov no interface .

Tsis tas li ntawd, dab tsi yog teeb tsa interface hauv Java?

Cov Teeb Interface . A Teeb yog ib qho Collection uas tsis tuaj yeem muaj cov khoom sib npaug. Nws ua qauv lej teeb abstraction. Cov Teeb interface tsuas muaj txoj hauv kev tau txais los ntawm Kev Sau thiab ntxiv cov kev txwv uas txwv tsis pub cov khoom sib npaug.

Tsis tas li ntawd, dab tsi yog qhov interface hauv Java nrog piv txwv? Zoo li chav kawm, ib interface tuaj yeem muaj txoj hauv kev thiab hloov pauv, tab sis cov txheej txheem tau tshaj tawm hauv ib qho interface yog los ntawm default abstract (tsuas yog txoj kev kos npe, tsis muaj lub cev). Interfaces qhia tias chav kawm yuav tsum ua li cas thiab tsis ua li cas. Nws yog lub hom phiaj ntawm chav kawm. A Java tsev qiv ntawv piv txwv yog, Comparator Interface.

Tsis tas li ntawd, peb puas tuaj yeem hloov kho cov khoom teeb tsa hauv Java?

1 Teb. Feem ntau, kev sau nrog qee yam ntawm cov qauv sab hauv tsis saib rau kev hloov pauv hauv lawv cov ntsiab lus, thiab lawv cov qauv yuav raug puas tsuaj yog koj hloov kho cov ntsiab lus (nyob rau hauv txoj kev uas hloov cov cuab yeej uas tus qauv yog raws li). Qhov no tuav rau TreeSet ib yam nkaus.

Dab tsi yog cov chav kawm siv cov npe thiab teeb tsa interface?

2) Sau npe tso cai duplicates thaum Teeb tsis pub cov ntsiab lus duplicate. Tag nrho cov ntsiab lus ntawm a Teeb yuav tsum yog tshwj xeeb yog tias koj sim ntxig lub duplicate keeb nyob rau hauv Teeb nws yuav hloov tus nqi uas twb muaj lawm. 3) Sau npe Kev siv: ArrayList, LinkedList thiab lwm yam. Teeb Kev siv: HashSet, LinkedHashSet, TreeSet thiab lwm yam.

Pom zoo: