Convert LowerCase String into UpperCase

How to Convert Convert LowerCase String into UpperCase

This tutorial explains how to Convert LowerCase String into UpperCase in different locale and default locale as well.
There is a method toUpperCase() which converts lowercase String into uppercase String.

Method Declaration:

(1) String toUpperCase()
Converts all of the characters in this String to upper case using the rules of the default locale. This method is equivalent to toUpperCase(Locale.getDefault())

(2) String toUpperCase(Locale locale)
Converts all of the characters in this String to upper case using the rules of the locale. 

Demo Examples to Convert LowerCase String into UpperCase

package com.mathapachi;

import java.util.Locale;

public class UpperCaseToLowerCaseDemo {

	public static void main(String[] args) {

		String str = "sndghsfdhdf";
		String upperCase = str.toUpperCase(); 
		System.out.println("UpperCase of "+str+ " is "+upperCase);
		
		String str1 = "ABhdghCD";
		String upperCase1 = str1.toUpperCase(); 
		System.out.println("UpperCase of "+str1+ " is "+upperCase1);

		String str2 = "title";
		String upperCase2 = str2.toUpperCase(Locale.FRANCE); 
		System.out.println("UpperCase of "+str2+ " is "+ upperCase2);

	}

}

The output of the above program is as below:

UpperCase of sndghsfdhdf is SNDGHSFDHDF
UpperCase of ABhdghCD is ABHDGHCD
UpperCase of title is TITLE

NOTE:

Sometimes, it is possible that the UpperCase of a String in a particular locale is different from UpperCase of that String in default ENGLISH Locale

Convert Json into Object

How to Convert Json into Object Using gson jar

This demo program illustrates how to convert json String into Object. This program uses fromJson() method of Gson class.It converts json string into Employee object.

JAR USED : gson-2.2.4.jar

Method declaration:

  (1) public  T fromJson(String json, Class classOfT) throws JsonSyntaxException
This method deserializes the specified Json into an object of the specified class.

Use this method if the json is in String form.

(2) public  T fromJson(Reader json,Class classOfT) throws JsonSyntaxException,JsonIOException
This method also deserializes the Json read from the specified reader into an object of the specified class.

Use this method if the json is the reader producing the Json from which the object is to be deserialized

Demo Example using methos (1) above (When the json is in String form):

Employee.java

package com.mathapachi.beans;

public class Employee {

	private String name;
	private String company;
	private Integer salary;
	
	
	public Employee(String name, String company, Integer salary) {
		this.name = name;
		this.company = company;
		this.salary = salary;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCompany() {
		return company;
	}
	public void setCompany(String company) {
		this.company = company;
	}
	public Integer getSalary() {
		return salary;
	}
	public void setSalary(Integer salary) {
		this.salary = salary;
	}
	
}

ConvertJsonIntoObject .java

package com.mathapachi.json;

import com.google.gson.Gson;
import com.mathapachi.beans.Employee;

public class ConvertJsonIntoObject {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		  String jsonStr = "{\"name\":\"Mathapachi\",\"company\":\"google\",\"salary\":20000}";
		  Gson gson = new Gson();
		  Employee emp = gson.fromJson(jsonStr, Employee.class); 
		  System.out.println("Name = "+emp.getName());
		  System.out.println("Company = "+emp.getCompany());
		  System.out.println("Salary = "+emp.getSalary()); 
	}

}

The above code will give the below output:

Name = Mathapachi
Company = google
Salary = 20000