G
Googmeister
Anyone know why String in Java 1.5 does not implement
the Iterable<Character> interface? It seems reasonable
to write
String text = "Hello, World";
for (char c : text) {
// do something with c
}
and avoid charAt() and length(). It would do a lot of
unnecessary autoboxing, but if arrays are Iterable,
why not Strings?
Is the autoboxing somehow bypassed when iterating
over arrays of primitive types?
Thanks for any insight.
the Iterable<Character> interface? It seems reasonable
to write
String text = "Hello, World";
for (char c : text) {
// do something with c
}
and avoid charAt() and length(). It would do a lot of
unnecessary autoboxing, but if arrays are Iterable,
why not Strings?
Is the autoboxing somehow bypassed when iterating
over arrays of primitive types?
Thanks for any insight.