java 格式化输出
一、java.util.Formatter
java.util.Formatter 是JDK1.5新增的类库,功能很强大,但是不好掌握,就像下棋一样,知道如何走棋子,和熟练应用完全是两码事。
格式化主要用在文本输出方面,比如,数字、日期、金额等,还有类似超市的购物单小票等等,都会用到格式化输出的工具。在此类没出现之前,只能通过空格缩进或这个制表符来对单据等格式做一些控制,现在只要掌握java.util.Formatter,一切问题就解决了。
shut!有关这个类javadoc文档太难看懂了下面的例子:
import java.util.Calendar;
import java.util.Formatter;
import java.util.GregorianCalendar;
/**
* Formatter测试
*
* @author leizhimin 2009-7-16 16:31:02
*/
public class TestFormatter {
public static void main(String[] args) {
//%[argument_index$][flags][width][.precision]conversion
Formatter f1 = new Formatter(System.out);
//格式化输出字符串和数字
f1.format("格式化输出:%s %d", "a", 1235);
System.out.println("\n--------");
//日期的格式化
Calendar c = new GregorianCalendar();
f1.format("当前日期:%1$tY-%1$tm-%1$te", c);
System.out.println("\n--------");
&nbs
相关文档:
1. 代理模式主要有两种:静态代理和动态代理
2. 静态代理:
比如要在输出“HelloWorld”前打印一个字符串“Welcome”
A:先定义一个接口类
Java代码
package ttitfly.proxy;
public interface HelloWo ......
Object Ordering
A List l may be sorted as follows.
Collections.sort(l);
If the List consists of String elements, it will be sorted into alphabetical order. If it consists of Date elements, it will be sorted into chronological order. How does this happen? String and Date both implement the Compara ......
Java软件有MIDP2.0和MIDP1.0两种。因此,我们在安装Java软件时,首先需要根据软件提供的信息判断软件是否适合自己的手机,从而避免安装之后无法使用的情况发生。 此外,有些软件可能会与手机内已经安装的软件有冲突,在安装前也应仔细看清楚相关说明。
安装常见问题解答
症状1:安装完成后却自动删除,或显示无 ......
第1章 Java语言概述
1.1 知识概括
1.2 实验练习
1.2.1 一个简单的应用程序
class里不能再有class,无论有没有public修饰,class都是平行关系,在bin文件夹中会产生各自的字节码文件。同一个.java源文件中至多有一个public class,如果不想再一个源文件中写多个类,就各自写源程序,并把类公用,即用public修饰。
1.2.2 ......