Change case of characters in given string in java



In this core java programming tutorial we will write a program to Change case of characters in given string in java


Write a program that will help us in changing case of characters in String in java.


Example in java>
input String : Java Made So Easy
output         : jAVA mADE sO eASY



Must know >


ASCII value of
A-Z = 65-90 where
A=65, Z=90


and ASCII value of
a-z = 97-122 where
a=97, z=122


Full Program/SourceCode / Example to Change case of characters in given string in java >
/** Copyright (c), AnkitMittal www.JavaMadeSoEasy.com */
class ChangeStringCharactersCaseExample {
   public static void main(String args[]) {
          String inputString = "Java Made So Easy";
          System.out.println("input String : "+inputString);
          System.out.println("output    : "+changecase(inputString));
         
   }
  
   /**
   * method returns changed cases of characters in String.
   */
   static String changecase(String inputString) {
          char ar[]=inputString.toCharArray();
         
          for (int i = 0; i < ar.length; i++) {
                
                 if (ar[i]>=65 && ar[i] <=90) { //convert upperCase to lowerCase
                       ar[i] += 32;
                 } else if(ar[i]>=97 && ar[i] <=122){ //convert lowerCase to upperCase.
                       ar[i] -= 32;
                 }
                
          }
          return new String(ar);
   }
  
}
/*OUTPUT
input String : Java Made So Easy
output    : jAVA mADE sO eASY
*/

So, in this core java programming tutorial we wrote a program to Change case of characters in given string in java

Previous program                                                                  Next program


Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.



RELATED LINKS>



77) write program to Customize Serialization process by defining writeObject()  method & DeSerialization process by defining readObject() method
78) wap to Serialize and DeSerialize object by implementing Externalizable interface- override writeExternal() and readExternal() methods
79) program to define Impact of not defining serialVersionUID in class and  avoiding InvalidClassException
80) If member of class does not implement Serializable interface - than  NotSerializableException is thrown
81) program to make subclass avoid Serialization if its superClass has implemented Serialization interface
82) Avoid Deserialization process from creating another instance of Singleton class
83) wap to Deep copy in java using Serialization and Deserialization
84) How to handle exception thrown from static block in java? Why throw not allowed in static block
85) program of Exception chaining in java
86) What are checked (compile time exceptions) in java
87) write Try-with-resources in java
88) write program to show Catch block and Automatic Resource Management in java 7 (Multi catch syntax)

eEdit
Must read for you :