Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.format() is Capitalizing Arguments

I have a String format String:

String.format("CREATE TABLE %s ("
    + "%S INTEGER PRIMARY KEY AUTOINCREMENT, %s INTEGER NOT NULL, %s TEXT NOT NULL)",
    SPORT_TABLE, SPORT_ID, SPORT_WSID, SPORT_TITLE);

But my second argument (SPORT_ID) is being capitalized. Why is this happening? What can I do to fix this?

like image 563
Alex Gittemeier Avatar asked Jul 25 '13 19:07

Alex Gittemeier


People also ask

What is string format () used for?

In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string.

Why is string with a capital letter?

By convention, java Objects have capitalized first-letter names (e.g. String), while primitives have lower case names (e.g. int, float, double, etc.) Save this answer.

What is format () in Python?

Python format() In this tutorial, we will learn about the Python format() function with the help of examples. The format() method returns a formatted representation of the given value controlled by the format specifier.

Is string capitalize in Java?

In this quick tutorial, you will learn how to capitalize the first letter of a string in Java. Unfortunately, the String class does not provide any method to capitalize strings.


1 Answers

It is a perfectly documented behavior even if not a well known one (probably because it's neither an obvious need nor something very useful).

From the javadoc :

The following table summarizes the supported conversions. Conversions denoted by an upper-case character (i.e. 'B', 'H', 'S', 'C', 'X', 'E', 'G', 'A', and 'T') are the same as those for the corresponding lower-case conversion characters except that the result is converted to upper case according to the rules of the prevailing Locale. The result is equivalent to the following invocation of String.toUpperCase()

like image 155
Denys Séguret Avatar answered Sep 23 '22 10:09

Denys Séguret