Display the second line of a string in java

Given a String like :

String str= "line1
line2
line3
line4";

How to display one specific line? For example the third one, like

System.out.println([...]str[...]);

which in terminal will display:

line3

Answers


You can use the split statement. It separates strings by a given regex. In this case the regex would be \n:

String[] lines;

  String regex= "\\n";
  lines = str.split(regex);

you can then acces line 3 by using:

String line3 = lines[2];

Need Your Help

python group by two columns, extract first element by one index

python group-by pandas multi-index

If I use groupby function, e.g. Data.groupby(['id','company']).size(), it will give a result like:

sql syntax in ms. access and vb.net

sql vb.net ms-access

i want ask you about sql syntax in microsoft access.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.