Java Formatter format Strings

Introduction

To format a string, use %s.

The following code format String value in both upper case and lower case.

import java.util.*; 
 
public class Main { 
  public static void main(String args[]) { 
    Formatter fmt = new Formatter(); 
 
    fmt.format("Formatting %s is %S%c", "with Java", "easy", '!'); 
 
    System.out.println(fmt); //  w  w  w .j ava 2s  .  c o m

    fmt.close();
  } 
}



PreviousNext

Related