I have a string array that looks something like {"a","b","c","d"}
. Each two consecutive items are pairs and I want to iterate through the array and be able to consider the two strings together. Currently I'm thinking of having a loop and a count to work out where I am in the iteration but is there a simpler/better way?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
A few possibilities.
1)
2)
I like the loop that increments two at a time as well, but just to add something a little different, you could also make use of
IntStream
:Outputs:
So I assume you mean
a -> b
andc -> d
. The classic way to deal with this is a loop that increments two at a time:What about using some math?
If the array is provided by a caller, then you might want to handle the case where a.length is not even.