0

I have a empty list and iam adding various data,,the thing is all the values showing in one line only,so can i use line break in list

public list<String> strsss=new list<String>();
strsss.add('Name'+'BillingCity');

this will be output as Name BillingCity I want it as

  Name
  BillingCity

thanks in advance

  • What do you mean by "output as"? Can you post code that would output that? – kurunve Sep 26 '16 at 12:21
  • if i return my list,it shows ,e above output – Satya Sep 26 '16 at 12:26
  • 1
    Please tell where you want to use it. You can put new line character in string, but it can behave differently (& at times unpredictably ) depending on where its used. – mritzi Sep 26 '16 at 12:43
0

Much of this depends on where and how you're outputting your code. But yes, you could put a newline character in following the Name using \n. That can be done via Apex.

As I recall, not all text strings will support all characters for storage. A long text string will support a new line character but a 255 character or less text string won't. Inside of Apex, any string will support it, but when you go to save it to a field, there could be an issue is what sticks in my mind. You'd need to give it a try. How it displayed would be dependent on the formatting of how you were to output your text.

  • fields of type Text Area and Text Area (long) support new line – cropredy Sep 26 '16 at 17:18
  • Right! That's what I was thinking, that it had to be a text area, but didn't phrase it quite that way. Thanks for the helping me clarify it. :) – crmprogdev Sep 26 '16 at 19:57
0

Am assuming this only to display. if yes,

Option 1:

List<String> cityList = new List<String>();
for(Account acc : [select ..from account]) {
  cityList.add('name');
  cityList.add(acc.billingcity);
}

Option 2:

public List<String> cityList {get;set;}
public String name='name';
String
for(Account acc : [select..from account]) {
cityList.add(acc.billingcity);
}

//vf page

<apex:repeat value="cityList" var="city">
    <apex:outputText value="{!name}"/>
    <apex:outputText value="{!city}" />
</apex:repeat> 
0
public list<String> strsss=new list<String>(); 
strsss.add('Name\n'+'BillingCity');

Try this. It will work.

  • How do you know it will work when the op has not provided usage context – Eric Sep 26 '16 at 21:05
  • Please read the question and the answer provided – Praveen Biyani Sep 27 '16 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.