• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

String.format

 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

format(Locale l, String format, Object... args)


Please can some explaining this mehtod with example. I am not able understand this method.
Please help me.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What don't you understand? This specific overload or the whole concept of formatting strings? Formatting strings is a process of combining a string (called a 'format string') containing some special characters ('format specifiers') with a list of arguments, which gives a formatted string as output. The whole specification for formatting in Java is pretty long and somewhat complicated. You will probably find all details you need in the JavaDoc of the java.util.Formatter class.

As to the String#format using Locale, it just formats all locale-specific arguments provided to the method (date, time, numbers etc.) according to the given Locale.

A (very simple example of format:

The code above will output: The value of 'i' is: 6
(printf works same as String#format)
In this example:
"The value of 'i' is: %d" is a format string
%d is a fomat specifier for decimal integer
i is argument, whose value is substituted for %d
[ August 13, 2008: Message edited by: Dariusz Kordonski ]
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you pass Array Object to this method which map all the values with the format string ?
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic