2020-11-19

  • Post author:
  • Post category:其他


两个for循环写法的比较,第2种会超时= =

参考文档:

https://www.cnblogs.com/winner-0715/p/7363725.html

结论:循环ArrayList时,普通for循环比foreach循环花费的时间要少一点;循环LinkList时,普通for循环比foreach循环花费的时间要多很多!!

for (int num : nums1)
{
     set.add(num);
}
for(int i=0;i<nums1.length;i++)
{
    set.add(nums1[i]};
}

List快速转换为数组:

List<Integer> res = new ArrayList<>();
res.add(1);
res.add(2);

res.stream().mapToInt(Integer::intValue).toArray();

字符串转换为数组:

String pattern='abcd';
String chars='cat dog dog cat';
char[] charp = pattern.toCharArray();
String[] chars = s.split(" ");
HashMap<Character,String> map = new HashMap<Character,String>();



版权声明:本文为yarden0原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。