I want to split String without creating string array. Below is code
String output = "abc 0 0 222.1.2.3:12345 1.1.3.5:20000 55555";
JSONArray listeningIpsArray = new JSONArray();
if (StringUtils.isNotEmpty(output)) {
String[] lines = output.split("\n");
for (String line : lines) {
if (StringUtils.isNotBlank(line)) {
String[] port = output.split("\\:");
for (String l : port) {
listeningIpsArray.put(l.trim());
}
}
}
// String a[] =output.split("\\:");
System.out.println("String" + listeningIpsArray);
}
}
When I run this code I got output as below. Array of 3 String elements is being created
String["abc 0 0 222.1.2.3","12345 1.1.3.5","20000 55555"]
But I need output in only one string as below.
String["abc 0 0 222.1.2.3 12345 1.1.3.5 20000 55555"]
Space between IP and port.
How can I do this ?
String[] port = output.split("\\:");if you don't want that?