• 请不要在回答技术问题时复制粘贴 AI 生成的内容
siruoqi
V2EX  ›  程序员

问个小问题,为什么 HashMap set.contains()方法, contain 加 s,其他方法都不加

  •  
  •   siruoqi · Oct 23, 2023 · 2157 views
    This topic created in 1115 days ago, the information mentioned may be changed or developed.

    set.add("apple");

    set.add("banana");

    set.contains("apple"));

    map.put("one", 1);

    map.put("two", 2);

    map.get("one"));

    比如说,JAVA 的 HashMap 和 HashSet ,有关集合和映射的方法中

    增加元素是 add 和 put ,获取元素是 get ,都没有加第三人称单数的 s

    唯独 set 的 containS 方法,末尾有 S

    这是为啥

    3 replies  •  2023-10-23 14:57:31 +08:00
    dingwen07
    dingwen07
    Oct 23, 2023 via iPhone
    1
    额……可能英语就是这样的吧
    jsq2627
    jsq2627
    PRO
    Oct 23, 2023❤️11
    2
    add/put/get ,map 属于被操作的对象,在宾语位
    contains ,map 在主语位

    类似的有 JS 的 array.includes, string.startsWith, string.endsWith, map.has
    wanguorui123
    wanguorui123
    Oct 23, 2023
    3
    vt 和 v 的区别
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4778 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:13 · PVG 14:13 · LAX 22:13 · JFK 01:13
    ♥ Do have faith in what you're doing.