Java – create arrays using a for loop
•
Java
Whether it is possible to create arrays in a similar style in Java, I have been searching and can't find anything
int[] foo = { for(String arg:args) return Integer.parseInt(arg); };
Solution
No, but you can do this:
int[] foo = new int[args.length]; for(int i = 0; i < foo.length; i++) { foo[i] = Integer.parseInt(args[i]); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码