简体   繁体   中英

java System.out.print format style

System.out.println(tree.item +"\t\t\t"+tree.list);
 as [26, 27, 38] associated [1] at [17, 18] attack [10] 

But i want print like this

 as [26, 27, 38] associated [1] at [17, 18] attack [10] 

I dont have access to the code you want to but I can suggest to use the - which means basically left indentation

Example:

String[] item = new String[] { "Audi", "BMW", "VW", "Ferrari", "Cherry QQ" };
float[] price = new float[] { 18000.0f, 24000.0f, 2100.50f, 786400.1f, 120.70f };

for (int i = 0; i < price.length; i++) {
    System.out.printf("%2d. %-10s €%.2f\n", i + 1, item[i], price[i]);
}

the result will look left justified like

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM