String conversion

String conversion

I want to convert a string of mix cases(lower and upper case) to vice versa.

ex.

HellO should be printed to hELLo.

the string comes from user using datainputstream. Also sending individual chars of string to toUpperCase() and toLowerCase() not possible.

View Answers

March 7, 2011 at 5:21 PM

Java String Case Converter

import java.util.*;

class StringExample {
        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                System.out.print("Enter string: ");
                String str = input.nextLine();
                StringBuffer sb = new StringBuffer();
                char ch[] = str.toCharArray();
                for (int i = 0; i < ch.length; i++) {
                        if (ch[i] == ' ') {
                                sb.append(" ");
                        }
                        if (Character.isLowerCase(ch[i])) {
                                char cha = Character.toUpperCase(ch[i]);
                                sb.append(Character.toString(cha));
                        } else if (Character.isUpperCase(ch[i])) {
                                char cha = Character.toLowerCase(ch[i]);
                                sb.append(Character.toString(cha));
                        }
                }
                System.out.println(sb.toString() + " ");
        }
}









Related Tutorials/Questions & Answers:
String conversion
String conversion  I want to convert a string of mix cases(lower and upper case) to vice versa. ex. HellO should be printed to hELLo. the string comes from user using datainputstream. Also sending individual chars of string
javascript integer to string conversion
javascript integer to string conversion  How to Javascript Integer to String Conversion   <script type="text/javascript">..., this works result = a + b + c; printWithType(result); //123 string
Advertisements
Conversion of String to Integer
Conversion of String to Integer  public class Test { public static void main(String[] args) { int countA = 0; int countB = 0...'; chr++) { (int) String "count"+chr = 0
HSSFCell to String type conversion
HSSFCell to String type conversion  Hello, Can anyone help me convert HSSFCell type to string. There is a solution in the following URL, but the method getWorkbook() is not defined for the class HSSFCell. Thanks in advance
String to Date Conversion - Java Beginners
String to Date Conversion  Hi , I am retreiving time stamp of a file and then inserting it into ACCESS DB. I am converting it to string format.... Hence I need some help for converting my String Date format to Date format, so
java code for conversion of arraylist to string - Development process
java code for conversion of arraylist to string  Hi, i have... into seperation.fo that i want to convert into string, after that split the string... : import java.util.*; class ArrayListToString { public static void main(String
PHP Array to String Conversion
PHP Array to String Conversion Sometimes data arrive in array which has... is used to convert the array into string. In PHP, conversion of an array to string... warning or error message. PHP Array to String Conversion Example 1:ADS
Conversion from string data type into different data types.
Conversion from string data type into different data types.  string str="World id Beutifull"; char chr[20]; char* chrctr ; Qustion is -How to store the 'str' value in 'chr' and 'chrctr'? int abc; sprintf(abc ,"%s",str
Data Conversion from String to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from String primitive type to another data type like int, boolean and char etc
Conversion from short to String
Conversion from short to String: In this tutorial we will learn how to convert... a short type value from console and provides a conversion to String type. The line... Conversion from short type to String type---"); System.out.println("Enter short
String to Int Conversion
String to Int Conversion       This section illustrates you how to convert a string into its integer equivalent. To demonstrate the conversion of string into an integer we are taking
Conversion from byte to String
Conversion from byte to String: In this tutorial we will learn how to convert a byte type value to String type value. Description: This program will take a byte value from console and provides a conversion to String type data
Conversion from float to String
Conversion from float to String: In this tutorial we will learn how to convert... will take a float value from console and provides a conversion to String type data... Conversion from float type to String type---"); System.out.println("Enter float
Conversion from double to String
Conversion from double to String: In this tutorial we will learn how... will take a double value from console and provide the conversion to String type...("---Data Conversion from double type to string type---"); System.out.println
Conversion from long to string
Conversion from long to String: In this tutorial we will learn how to convert a long type value to String type value. Description: This program will take a long type value from console and provide the conversion to String type
Java : String Case Conversion
Java : String Case Conversion In this section we will discuss how to convert a String from one case into another case. Upper to Lower case Conversion...; + uCaseStr); } } Description : This example shows conversion of String from
Conversion from int to String
Conversion from int to String: In this tutorial we will learn how to convert an int type value to a String type. You will convert an int value  to String by using toString() method. Description: This program will take an int
Conversion from String to int
Conversion from String to int: In this tutorial we will learn how to convert a string type data to int type data. Description: This program will take a String value from mystring variable. The line int myint = Integer.parseInt
Conversion from String to byte
Conversion from String to byte: In this tutorial we will learn how to convert a string type data to byte type data. Description: This program will take a String value from mystring variable. The line byte mybyte = Byte.parseByte
Conversion from String to short
Conversion from String to short: In this tutorial we will learn how to convert a string type data to short type data. Description: This program will take a String value from mystring variable. The line short myshort
Conversion from String to long
Conversion from String to long: In this tutorial we will learn how to convert a string type data to long type data. Description: This program will take a String value from mystring variable. The line long mylong = Long.parseLong
Conversion from String to float
Conversion from String to float: In this tutorial we will learn how to convert a string type data to float type data. Description: This program will take a String value from mystring variable. The line float myfloat
Conversion from String to double
Conversion from String to double: In this tutorial we will learn how to convert a string type data to double type data. Description: This program will take a String value from mystring variable. The line double mydouble
Conversion from String to boolean
Conversion from String to boolean: In this tutorial we will learn how to convert a string type data to boolean type data. Description: This program will take a String value from mystring variable. The line boolean mybool
Conversion from String to char
Conversion from String to char: In this tutorial we will learn how to convert a string type data to char type data. Description: This program will take a String value from mystring variable. The line Character mychar
conversion
conversion  please give me the code to convert the particular string "messageType=3+sourceSystemId=0+destinationSystemId=0+NPA=1+prefix=0+phoneNumber=0+length=0+subLength=209+subCode=49+subType=1+subResult=0+subCause=0
conversion
conversion  please give me the code to convert the particular string "messageType=3+sourceSystemId=0+destinationSystemId=0+NPA=1+ prefix=0+phoneNumber=0+length=0+subLength=209+subCode=49+subType=1+ subResult=0+subCause=0
Java date to String, Convert date object into a string with a pattern
Convert date object into a string with a pattern This section illustrates you the conversion of date object into a string pattern. Java has provide many... string. For example, d -  denotes the day in month M- denotes the month
STRING.....
STRING.....  plzz sent me d code for counting vowels in a string... gui programme
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both... "String args[]" can mean a "string array called args which is an array
string
string  String helloString = new String(helloArray); System.out.println(helloString); i am unable to understand this. could u plz explain
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
String
String  how to add spaces with string functions.?   Hi... { public static String addSpaceToRight(String s, int n) { return String.format("%1$-" + n + "s", s); } public static String addSpaceToLeft(String s, int n
Data Conversion from int to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from int primitive type to another data type like String, boolean and char etc
Data Conversion from short to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from short primitive type to another data type like String, boolean and char etc
Data Conversion from byte to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from byte primitive type to another data type like String, boolean and char etc
Data Conversion from float to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from float primitive type to another data type like String, boolean and char etc
Data Conversion from double to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from double primitive type to another data type like String, boolean and char etc
Data Conversion from long to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from long primitive type to another data type like String, boolean and char etc
Convert Double To String
; This section learns you the conversion of double into string. The following program... Convert Double To String      ... The program  takes a variable of double type and convert it into the string form
String
characters in string?   import java.util.*; class RemoveDuplicateCharatcersFromString { public static String removeDuplicates(String s... < s.length(); i++) { String st = s.substring(i, i + 1
String
String  write down the code of remove any character from a given string without using any string function   please give me the code of remove any given character from a given string without using function
string
string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
string
*; class ExtractWords { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String: "); String st=input.nextLine(); String str[]=st.split
string
string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C...; public class StringTest { public static void main(String [] args
string
string  write a program to accept the string and store the reverse stream into another array and print
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  java prgm to find total occurence of a given string pattern in a sentence
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String

Ads