V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
siruoqi
V2EX  ›  程序员

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

  •  
  •   siruoqi · Oct 23, 2023 · 1598 views
    This topic created in 917 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
        1
    dingwen07  
       Oct 23, 2023 via iPhone
    额……可能英语就是这样的吧
    jsq2627
        2
    jsq2627  
       Oct 23, 2023   ❤️ 11
    add/put/get ,map 属于被操作的对象,在宾语位
    contains ,map 在主语位

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