JAVA?г?????5??????
???????????? ???????[ 2015/7/28 14:31:18 ] ???????????????? ???????????
??????????????????????????????
????????????????????? ear flaps ?? hats ?????? list???????????????????????????????????????????????????????? hats??
????</>
????List<IHat> hatsToRemove = new LinkedList<>();
????for (IHat hat : hats) {
????if (hat.hasEarFlaps()) {
????hatsToRemove.add(hat);
????}
????}
????for (IHat hat : hatsToRemove) {
????hats.remove(hat);
????}
??????? Iterator.remove ????
???????????????????????????????????????
????</>
????Iterator<IHat> hatIterator = hats.iterator();
????while (hatIterator.hasNext()) {
????IHat hat = hatIterator.next();
????if (hat.hasEarFlaps()) {
????hatIterator.remove();
????}
????}
??????? ListIterator ?????
????????????????????? List ??????list iterator ??????????????? ListIterator ???? iterator ????????????????????? add ?? set ??????ListIterator ???????? Iterator ????????????????????? Iterator ?? remove ???????????????? hat iterator ????????????? iterator ????——??? listIterator() ???????????????????????? ListIterator.remove ?? ListIterator.add ?????????? ear flaps ?? hat ?滻?????sombreros ???
????</>
????IHat sombrero = new Sombrero();
????ListIterator<IHat> hatIterator = hats.listIterator();
????while (hatIterator.hasNext()) {
????IHat hat = hatIterator.next();
????if (hat.hasEarFlaps()) {
????hatIterator.remove();
????hatIterator.add(sombrero);
????}
????}
??????? ListIterator?????? remove ?? add ???????滻????????? set ??????
????</>
????IHat sombrero = new Sombrero();
????ListIterator<IHat> hatIterator = hats.listIterator();
????while (hatIterator.hasNext()) {
????IHat hat = hatIterator.next();
????if (hat.hasEarFlaps()) {
????hatIterator.set(sombrero); // set instead of remove and add
????}
????}
???????Java 8?е? stream ????
?????? Java8 ?У???????????????? collection ???? stream??????????Щ???????? stream?????????????? stream api ????ι??? hats ????? ConcurrentModificationException?? hats = hats.stream().filter((hat -> !hat.hasEarFlaps()))
????</>
????.collect(Collectors.toCollection(ArrayList::new));
????Collectors.toCollection ??????????????μ? ArrayList????????????????? hats ????????????????????????????????????????????? ArrayList???????????????á?
??????? Java 8 ?е? List.removeIf ????
??????????? Java 8 ????????????????????—— removeIf ????:
????</>
????hats.removeIf(IHat::hasEarFlaps);
????????????? Iterator.remove ??????????????
???????????????
???????????????????? CopyOnWriteArrayList ?????? ArrayList????????????????? CopyOnWriteArrayList ????????????????? set??add??remove???????????????????????飬?????????????μ????汾???????????????汾????????????????????????? ConcurrentModificationException ???????????????????????——??????????????????μ?????
?????????????????????????????????? CopyOnWriteSet ?? ConcurrentHashMap??
????????????????????????????????????????????????? collection ????????? stream??????? stream ????????????? collection????? stream ??????????????? stream ??????????????? collection???????????????????????????? stream??
????</>
????List<IHat> filteredHats = hats.stream().peek(hat -> {
????if (hat.hasEarFlaps()) {
????hats.remove(hat);
????}
????}).collect(Collectors.toCollection(ArrayList::new));
????peek ??????????е??????????????????м??????????????????????????????????б???????????????????????????????????????????????Щ???潲????????
????4. Υ?
????????????????Э??????????????????????????????????????????????磬???????? hashCode ?? equals ??????????????? Java ???????е????м????????????? hashCode ?? equals ??????????????????????????????????????? exception ???????????????????????????????????????????????Σ?????????????????ó????????
???????????????????????????????????????????????????? UI ???顢???????????楨???????????????????????????????????Щ??????????????????????????????? hashCode ??equals ???????????????????????????????????????й??????????? HashMap ?? HashSet????????????????????????
?????????????????????? hash code ????????
?????????????????????? hash code?????????????????????????
??????????????????????????????? hashmap ?м??????????????′?????????????ζ???????? hash code ????????????
???????濴???????????????????
????</>
????public static class Boat {
????private String name;
????Boat(String name) {
????this.name = name;
????}
????@Override
????public boolean equals(Object o) {
????if (this == o) return true;
????if (o == null || getClass() != o.getClass()) return false;
????Boat boat = (Boat) o;
????return !(name != null ? !name.equals(boat.name) : boat.name != null);
????}
????@Override
????public int hashCode() {
????return (int) (Math.random() * 5000);
????}
????}
????????????????Boat ????д?? equals ?? hashCode ?????????????????????????? hashCode ?????ε??????????????????????????????????? hashset ????????????? Enterprise ??boat????????????????????????????????? boat??
????</>
????public static void main(String[] args) {
????Set<Boat> boats = new HashSet<>();
????boats.add(new Boat("Enterprise"));
????System.out.printf("We have a boat named 'Enterprise' : %b "?? boats.contains(new Boat("Enterprise")));
????}
???????????????????? finalize ?????????????? Java ????????????????????????
????finalize ????????????? JavaTM ?????????κ??????????????κη???????????????????????????????????????????????????????????????????????????????????????????finalize ?????ж??????????а???????????????????????????? finalize ????????????????????????????????????????????磬???????/??????????? finalize ???????????? I/O ???????????????????ж??????
???????????????????????????????? finalize ???????????????????????÷?????????????????????????????????????? GC ??????????????? finalize ?????????佫????????
????5. ?????????????????????
???????? Java ?????????????????????????????????? R ??????????? R ???????????????????????? Java ?????????????????????????????????Java ??1.5?汾???????????????????????????????????????????????????????????????????????????????????????????????????????
????</>
????List listOfNumbers = new ArrayList();
????listOfNumbers.add(10);
????listOfNumbers.add("Twenty");
????listOfNumbers.forEach(n -> System.out.println((int) n * 2));
??????????????????????б??????????? ArrayList??????????????????????????????????????κζ??????????н??????????????? int ????????? 2????????????????????????????
???????????????????????????????л???????????????????????????????????????Ρ???????????????????????????????????????д?????????
???????????????????????????е????????????????
????</>
????List<Integer> listOfNumbers = new ArrayList<>();
????listOfNumbers.add(10);
????listOfNumbers.add("Twenty");
????listOfNumbers.forEach(n -> System.out.println((int) n * 2));
???????????????????彎???????У?
????</>
????List<Integer> listOfNumbers = new ArrayList<>();
?????????????????????????????????????????????洢???ε?????????????????????????????????????????????????б?????? Twenty ?????????С???????????????????????????????????????????????????п????????????????????????????μ???????????????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????