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.
如果我想制作一个(树)集并用 2000 个整数填充它。从 0 开始,然后添加 1,2,3,4...2000。最好的方法是什么?
我可以
Set set = new TreeSet<Integer>(); set.add(0); set.add(1); set.add(2); //...
或使用 add(i);i++;
但是有没有更简单/更短的方法?
谢谢!
并非如此,Java 中没有 bob=[0...2000] 快捷方式。
Set set = new TreeSet<Integer>(); for(int i = 0; i <= 2000; ++i) set.add(i);
Set set = new TreeSet<Integer>(); // add Integers 0,1,...1999 for(int i=0;i<2000;i++){ set.add(new Integer(i)); }