On Sep 5, 1:42 pm, miga <[EMAIL PROTECTED]> wrote:
> On Sep 5, 1:25 pm, "Krupinski Norbert"
And the same with Array:
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String firstString = "aaa";
String secondString = "bbb";
String[] myStrings = new String[2];
myStrings[0] = firstString;
myStrings[1] = secondString;
System.out.println("Before swap - firstString = " +
firstString + " secondString = " + secondString);
swap(myStrings);
firstString = myStrings[0];
secondString = myStrings[1];
System.out.println("After swap - firstString = " + firstString
+ " secondString = " + secondString);
}
static void swap(String[] myStrings) {
String temporaryString = myStrings[1];
myStrings[1] = myStrings[0];
myStrings[0] = temporaryString;
}
}
Even the same schema:
1 - First you construct something mutable based on the strings
2 - You swap the internal of mutable object
3 - You reassign the values of strings to the result of the swapped
mutable object.
Or you use specific external API which has mutable strings, such as
Apache. You will be no more in pure Java but why reinvent the wheel?
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---