Replace for loop with for-each.
The for-each loop, introduced in release 1.5, gets rid of the clutter
and the opportunity for error by hiding the iterator or index variable
completely. Note that there is no performance penalty for using the
for-each loop. In fact, it may offer a slight performance advantage
over an ordinary for loop in some circumstances, as it computes the
limit of the array index only once.
Test: Build and install Nearby module to check, atest NearbyUnitTests
BUG: 216079944
Change-Id: Icaa109c720807b94c4d955a604544fa4858dd360
diff --git a/nearby/service/java/com/android/server/nearby/util/Hex.java b/nearby/service/java/com/android/server/nearby/util/Hex.java
index c827ec5..446204e 100644
--- a/nearby/service/java/com/android/server/nearby/util/Hex.java
+++ b/nearby/service/java/com/android/server/nearby/util/Hex.java
@@ -30,8 +30,8 @@
public static String bytesToStringLowercase(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
int j = 0;
- for (int i = 0; i < bytes.length; i++) {
- int v = bytes[i] & 0xFF;
+ for (byte aByte : bytes) {
+ int v = aByte & 0xFF;
hexChars[j++] = HEX_LOWERCASE[v >>> 4];
hexChars[j++] = HEX_LOWERCASE[v & 0x0F];
}