很多使用原始类型的地方,其实也可以使用java.lang.Number类型的对象,并且通常是能够自动转换的
Number.parseXXX,和Number.valueOf可以得到该类型对象
java.io.PrintStream
类中有两个方法,printf和foumat,可以用来替代print和println
format(String format, Object... args)//并且有重载
巧了,System.out正好是PrintStream类型
System.out.format("The value of " + "the float variable is " + "%f, while the value of the " + "integer variable is %d, " + "and the string is %s", floatVar, intVar, stringVar);
关于%后面都能加什么,可以查看java.util.Formatter类
也可以用java.text.DecimalFormat类,来控制前导0,后导0,前后缀,分隔符等
import java.text.*; public class DecimalFormatDemo { static public void customFormat(String pattern, double value ) { DecimalFormat myFormatter = new DecimalFormat(pattern); String output = myFormatter.format(value); System.out.println(value + " " + pattern + " " + output); } static public void main(String[] args) { customFormat("###,###.###", 123456.789); customFormat("###.##", 123456.789); customFormat("000000.000", 123.78); customFormat("$###,###.###", 12345.67); } }
The output is:
123456.789 ###,###.### 123,456.789 123456.789 ###.## 123456.79 123.78 000000.000 000123.780 12345.67 $###,###.### $12,345.67
java.lang.Math类包含了更多的算术运算,所有方法都是静态的,可以
import static java.lang.Math.*;//导入静态成员,可直接使用
Math.random()方法返回[0.0,1.0)的一个随机数,如果想生成多个,要用java.util.Random的实例方法
java.lang.Character类是char的包装类,但并不是Number的子类
java.lang.String类表示字符串,也就是字符序列
对每个字串字面量,编译器都会生成一个String对象,另外也可以调用它的13种构造手动生成
所有的Number,Character,String类型对象,都是不可更改的,所以String下面的很多方法都是生成了新的String
+操作符可以用来连接String,或者其他类型,如果是对象的话,会调用toString()方法
String字面量不能跨行书写,所以只能用+连接起来
String.format()方法返回另一个String
String fs; fs = String.format("The value of the float " + "variable is %f, while " + "the value of the " + "integer variable is %d, " + " and the string is %s", floatVar, intVar, stringVar); System.out.println(fs);
String.substring(4,5)指的是下标[4,5)的子串
StringBuilder提供的是变长字串,长度和内容可随时更改
StringBuilder(String)构造,和toString()方法,提供了二者的相互转换
相关推荐
ns_strings_zh_storyline.xml
ns_strings_zh.xml
计算机组成与结构:DS and AL_Lecture4_Strings.ppt
with_sweat: 这项工作目录Javascript Basics2Variables2Arrays3Operators4Functions5Loops7If - Else Statements7Strings7Regular Expressions9Numbers and Math10Dealing with Dates12DOM Node14Working with the ...
The Java Programming Language Architectural Tradeoffs Future Trends On the CD-ROM The Resources Page 2 Platform independence Why Platform Independence? Java's Architectural Support for Platform ...
ns_strings_zh_platinum.xml
本地化::globe_showing_Americas:本地化存储库,用于在Crowdin和GitHub之间同步100%翻译的文件
鲁比·科恩斯(Ruby Koans) // 去做 // 去做 Koan名称 完全的? about_asserts :check_box_with_check: ... about_true_and_false about_triangle_project about_exceptions about_triangl
1,读取项目中的所有strings.xml文件并导出为excel得到excel1。 2,可以将同样结构的excel2中的内容同步到excel1。 3,将所有excel1中的内容以自行配置(StringsToExcel.java)的文件夹(如"values-ko-rKR", "values-ja...
Then, master the usage of key language elements, such as strings and collections. Finally, grasp how Swift supports modern application development using advanced features, such as built-in Unicode ...
从字符集中获取所有排列: Strings_and_Numbers Permutations ====== 数字系统转换器: Strings_and_Numbers : RadixConverter ====== 处理任意长度的数字: Strings_and_Numbers : BigDigit 实现了以下操作...
In addition, we'll also teach you how to setup and use the Code Blocks IDE, which will help you greatly when programming in the C language. In this book you'll learn: Introduction to C Programming ...
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.21' not found 操作方法:#rm /usr/lib/x86_64-linux-gnu# rm libstdc++.so.6 #ln libstdc++.so.6.0.20 libstdc++.so.6 #strings /usr/lib/x86_...
Handling strings with R language
01_Arrays_and_Strings: 02_Linked_Lists: 03_Stacks_and_Queues: 04_Trees_and_Graphs: 05_Bit_Manipulation: 08_Recursion_and_Dynamic_Programming: 10_Sorting_and_Searching: 16_中等:
handling capabilities, and the use of assertions to validate the expected behavior of code. <br>Chapter 13Strings and Regular Expressionsdescribes the built-in language and runtime support for ...
用matlab运行MD5代码utl_match_strings_regardless_of_the_order_of-letters 无论字母顺序如何,都匹配字符串。 关键词:sas sql join 合并大数据分析宏 oracle teradata mysql sas 社区 stackoverflow 统计人工智能...
Lesson 14: Working with Strings Lesson 15: Working with Dates and Times Lesson 16: Using Arrays and Collections Lesson 17: Using Enumerations and Structures Section III: Program Statements Lesson 18:...
漏洞 :lady_beetle: 赏金狩猎和渗透测试资源 该存储库包含来自世界各地的各种黑客的各种有效负载,工具,技巧,书籍和技巧。 跟我来 错误赏金技巧 工具 有效载荷 反壳 词汇表 内容发现 渗透测试笔记 ...