String Formatting + Blackberry + java

[亡魂溺海] 提交于 2019-12-08 19:00:30

Try using String.format() if it is there in the version of jdk you are using with blackberry

package org.life.java.so.questions;

/**
 *
 * @author Jigar
 */
public class StringFormatDemo {
    public static void main(String[] args) {
        String name = "Jigar";
        String header = String.format("Name \t Class \t Section \t Positoin");
        String dataRow1 = String.format("%s \t %s \t %s \t %s",name,"A","IT","JavaDev");
        System.out.println(header);
        System.out.println(dataRow1);
    }
}

Update:

As the above method is not there with your java env you can go for

javax.microedition.global.Formatter.formatMessage(...)

It seems to me that you try to create an email body that looks well aligned in a viewer. And I guess, you're using a proportional font (like times or helvetica/arial).

Webservices usually don't care if the table looks aligned but care if the message is aligned. Make sure, that the number of chars is each column is the same, even if the result looks ugly on the screen. So really shouldn't use the getFont().getAdvance() method to make Strings (almost) equal size but use String#size() instead for padding.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!