reverse Array From To Position - Java Collection Framework

Java examples for Collection Framework:Array Reverse

Description

reverse Array From To Position

Demo Code


//package com.java2s;

public class Main {
    public static void reverseArrayFromToPosition(Character[] list,
            int fromPos, int toPos) {
        //System.out.println("from Pos: " + fromPos + " to Pos" + toPos);
        int numIterations = (int) Math.ceil((toPos - fromPos) / 2.0);
        for (int x = fromPos; x < fromPos + numIterations; x++) {
            char temp = list[x];
            list[x] = list[toPos + fromPos - x];
            list[toPos + fromPos - x] = temp;
        }//from  w w  w. java  2  s  .  c  o m
    }
}

Related Tutorials