i trying write java class needs short possible (line-wise). within class, have following code:
char[] myarray = {'a', 'b', 'c', 'd'}; for(char c : myarray) ...
in order make shorter, iterating on same chars, thought might able this:
for(char c : {'a', 'b', 'c', 'd'}) ...
however, doesn't work , cannot find online show me how (i'm not sure search this).
is possible in different way? or can not made shorter?
if chars form consecutive pattern, can use
for (char c = 'a'; c <= 'd'; c++)
if don't, use
for (char c : new char[] {'c', 'a', 'b'})
or
char[] arr = {'c', 'a', 'b'}; (char c : arr)
or
for (char c : "cab".tochararray())
Comments
Post a Comment