Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialdeinzo leonardo
Courses Plus Student 353 Pointswhere clause in android
database.update(MemeSQLiteHelper.MEMES_TABLE,
updateMemeValues,
String.format("%s=%d", BaseColumns._ID, meme.getId()), null);
// What String.format("%s=%d", BaseColumns._ID, meme.getId()) exactly do!
// And i see some time Evan use %s=%s ! what is the difference ?
I stuck in this point , so please could any one explain the concept of (where clause) with String formatting in android, i know the concept of (where) and i can deal with it in SQL , but not with String formatting in java
2 Answers
James Simshaw
28,738 PointsHello,
String.format("%s=%d", BaseColumns._ID, meme.getId()) is a safer way to create the strings in this case. What this is doing is taking the BaseColumns._ID and setting that equal to the first placeholder in our string formatter("%s=%d"), which our formatter is saying to format the data given to it as a string, which BaseColumns._ID is a string so no conversions have to happen. Next we take the result of meme.getId() and set that to our second placeholder in our string variable, %d. In the end it creates a string like "id=3" when ran.
There are a lot of placeholders that can be used, but in this example %s is a string and %d is an integer(decimal number). So a formatter call of String.format("%s is learning about %s", "Someone", "databases") would produce the string "Someone is learning about databases"
Let me know if this clears things up and if you have further questions.
deinzo leonardo
Courses Plus Student 353 PointsHello James ,
Thanks very much for detailed explanation , it's become clear now God bless your day my friend .