Java 17 Recipes
Download 3.2 Mb. Pdf ko'rish
|
Java 17 Recipes
- Bu sahifa navigatsiya:
- 3-17. Summary
How It Works
When you require dynamic string content, the format() utility can come in handy. The built-in format() method allows one to position a placeholder within a string, such that the placeholder is replaced with dynamic content at runtime. The format method accepts a string and a series of variables that displaces the placeholders within the string with dynamic content at runtime. The placeholders must be designated specifically for the type of content with which they are displaced. Each placeholder must begin with a % character to denote a placeholder within the string. The placeholder can also contain flags, width, and precision indicators to help format the dynamic value. The following format should build each placeholder. %[flags][width][.precision]conversion_indicator The second solution demonstrates how to utilize the System.out.printf() method, which accepts the same arguments as the System.format() method. The main difference is that the System.out.printf() method is handy for printing formatted content. If your application requires storing a formatted value, you are more likely to use the String.format() method. Chapter 3 StringS 106 3-17. Summary This chapter covered the basics of working with strings. Although a string may look like a simple string of characters, it is an object that contains many methods that can be useful for obtaining the required results. Although strings are immutable objects, many methods within the String class contain a copy of the string, modified to suit the request. The chapter also covered a handful of these methods, demonstrating features such as concatenation, obtaining portions of strings, trimming whitespace, and replacing portions of a string. Chapter 3 StringS 107 © Josh Juneau, Luciano Manelli 2022 J. Juneau and L. Manelli, Java 17 Recipes, https://doi.org/10.1007/978-1-4842-7963-2_4 Download 3.2 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling