java string swap two characters

String originalString = "abcde";
//Strings are immutable
char[] c = originalString.toCharArray(); 
//Swap
char temp = c[0];
c[0] = c[1];
c[1] = temp;
//Result
String swappedString = new String(c);

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
string character swap in java replace 2 characters in string java swap two char in string java swap characters in java swap two charcters in java how to swap letters in string in java how to swap characters in string in java swap charcters in two strings java string swap characters java swap a character in string java replace two characters in string java how to swap character in string java swap characters in a string java swap 2 strings in java swap characters string java how to swap string characters in java swap two chars in string in java how to swap two characters in a string in java swap characters in string java function swap characters in string java cuntion swap to characters in string in java swapping characters in a string java java swap characters in string swap characters of a string java swap two string in java swap letters in string java java replace char with empty swap two letters in a word in java how to swap characters in a string in java swapping letters java java method for swapping characters in a string Method or function that swaps two string characters in java can we swap two characters in a string in java swap 2 characters in a string java java how to swap characters in a string swap string characters in java swap two characters in a string java swap two characters in string java swap characters in string java swap string in java swap value within string java stringbuilder swap characters java swap string characters swap 2 chars in a substring java string swap two characters
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source