Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我设计列表,我会像这样 - new ArrayList("1","2")。给它一个构造函数,并立即添加一些东西。为什么Java不这样做呢?
new ArrayList("1","2")
因为没有构造函数可以接受两个字符串或变量。要克服这个问题,您可以致电:new ArrayList<String>(Arrays.asList("1", "2"))
new ArrayList<String>(Arrays.asList("1", "2"))