我有一些带有一些组件的String数组,这个数组有5个组件,它有些不同.我想要做的是迭代该数组并获得第一个组件和该组件旁边的组件.所以我第一次得到组件编号1和组件编号2,第二次得到编号2和3,第三次得到编号3和4 ......依此类推,直到你到达最后一个组件.
我到底有多远:
String[] elements = { "a", "a","a","a" };
for( int i = 0; i <= elements.length - 1; i++)
{
// get element number 0 and 1 and put it in a variable,
// and the next time get element 1 and 2 and put this in another variable.
}
Run Code Online (Sandbox Code Playgroud)
我怎么能做到这一点?