JavaScript
Top 85 JavaScript Interview Questions and Answers for 2021
JavaScript also abbreviated as JS, is a high level server side programming language. JavaScript is...
StrSplit() method allows you to break a string based on specific Java string delimiter. Mostly the Java string split attribute will be a space or a comma(,) with which you want to break or split the string
public String split(String regex) public String split(String regex, int limit)Parameter
Below example shows how to split a string in Java with delimiter:
Suppose we have a string variable named strMain formed of a few words like Alpha, Beta, Gamma, Delta, Sigma – all separated by the comma (,).
Consider the following code of split method in Java –
class StrSplit2{
public static void main(String []args){
String strMain = "Alpha, Beta, Delta, Gamma, Sigma";
String[] arrSplit_2 = strMain.split(", ", 3);
for (int i=0; i < arrSplit_2.length; i++){
System.out.println(arrSplit_2[i]);
}
}
} Output: Alpha Beta Delta, Gamma, Sigma
Consider a situation, wherein you want to split a string by space. Let’s consider an example here; we have a split string Java variable named strMain formed of a few words Welcome to gtupapers.
public class StrSplit3{
public static void main(String args[]){
String strMain ="Welcome to gtupapers";
String[] arrSplit_3 = strMain.split("\\s");
for (int i=0; i < arrSplit_3.length; i++){
System.out.println(arrSplit_3[i]);
}
}
}
Output:
Welcome to gtupapers
JavaScript also abbreviated as JS, is a high level server side programming language. JavaScript is...
What is OOPS Concept in JavaScript? Many times, variables or arrays are not sufficient to simulate...
Here are Java Collections Interview Questions for fresher as well as experienced candidates to get...
The static can be: Static Variables Static Methods Static Blocks Of Code. Let's look at static...
What is Java? Java is a general-purpose, class-based, object-oriented programming language...
What is String "Length" Method in Java? This function is used to get the length of string in Java....