Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
swapping values in JAVA
Posted by Soumya Ranjan Rath on September 10, 2001 at 6:45 AM
Hi, This is regarding swapping in java. i am enclosing the working code for ur reference --------------------------- import java.lang.Object; import java.lang.*; public class Swapper{ public static Object[] swap(Object[] items) { if (items.length >= 2) { Object temp = items[0]; items[0] = items[1]; items[1] = temp; } return items; } public static void main(String[] args) { Object[] ab = new Object[] { "Soumya", "Ranjan" }; System.out.println("ab[0]=" + ab[0] + " ab[1]=" + ab[1]); ab = swap(ab); System.out.println("ab[0]=" + ab[0] + " ab[1]=" + ab[1]); } } ---------------------- Regards, Soumya
Replies:
|