A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/lang/string_format_locale.htm below:

Java.lang.String.format() Method

Java.lang.String.format() Method Description

The java.lang.String.format(Locale l, String format, Object... args) method returns a formatted string using the specified locale, format string, and arguments.

Declaration

Following is the declaration for java.lang.String.format() method

public static String format(Locale l, String format, Object... args)
Parameters Return Value

This method returns a formatted string.

Exception Example

The following example shows the usage of java.lang.String.format() method.

package com.tutorialspoint;

import java.lang.*;

public class StringDemo {

   public static void main(String[] args) {

      double piVal = Math.PI;

      /* returns a formatted string using the specified format string,
         and arguments */
      System.out.format("%f\n", piVal);
      
      /* returns a formatted string using the specified locale, format
         string and arguments */
      System.out.format(Locale.US, "%10.2f", piVal);
   }
}

Let us compile and run the above program, this will produce the following result −

3.141593
3.14

java_lang_string.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4