Java string line feed

Source: Internet
Author: User

Tring test = "fdsfgds, fdesfds, fds, fds, fdsfds, fdsf, fdsfds, fdsf, fds ";
I want to use "," to separate them and then wrap them. Three lines are displayed, for example, "fdsfgds, fdesfds, fds, here, test is the value returned from the page. The length is not fixed. If more than three entries are separated by commas, the line breaks. If less than three entries are separated, the line breaks.
For test, it can be any length separated by commas.


Public class Num {
 
Public Num (){
 
}
Public String [] init (String str) {// convert
String [] s = new String [str. length ()];
S = str. split (",");
Return s;
}
Public void show (String [] s) {// display
Int j = 0;
For (int I = 0; I <s. length; I ++ ){
System. out. print (s [I] + ",");
J ++;
If (j = 3 ){
J = 0;
System. out. println ("");
}
}
}
 
Public static void main (String [] args ){
String test = "fdsfgds, eee, fdesfds, fds, fds, fdsfds, fdsf, fdsfds, fdsf, fds ";
Num n = new Num ();
String [] s = n. init (test );
N. show (s );
 
}
}
Output result:
Fdsfgds, eee, fdesfds,
Fds, fds, fdsfds,
Fdsf, fdsfds, fdsf,
Fds,

Author "Mo"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.