vendredi 27 février 2015

How to create a fixed lenght blank String in a smart way?

I have the following situation and I am not sure if I am handling it in smart way.


So I have to create a textual file that contains some lines.


Each line is a String composed by the concatenation of some other strings.


Some of these string (that I have to concatenate) are taken from a model object (are the values of the fields definied into a model object).


Some other string have fixed value (with fixed lenght).


For example (into the method that create the concatenation) I could have something like this:



// FINAL BUILDED String:
String outputLine;

// FIELDS TO BE CONCATENATED:
String jobId = " ";
String address = myModelObject.getAddress();
String name = myModelObject.getName();

outputLine = jobId + address + name;


So, as you can see from the previous snippet, the jobId field have to be a fixed String composed by 8 blanks consecutive characters


My doubt is: is it correct or can I crete a fixed lenght String (composed by all blanks characters) in some smarter way? Maybe using an array of Char? But I am not sure that it is a smarter solution


Tnx


Aucun commentaire:

Enregistrer un commentaire