I use String.split () to separate some strings as IP addresses, but them returning an empty array, so I fixed my problem using String.substring () but I wonder why it doesn’t work as intended, my code:
public static String filtrarIPs(String ips, String filtro) {
String resultado = "";
String[] lista = ips.split(" ");
for (int c = 0; c < lista.length; c++) {
String[] ipCorta = lista[c].split(".");
if (ipCorta[1].compareTo(filtro) == 0) {
resultado += lista[c] + " ";
}
}
return resultado.trim();
}
He must return String[] as {"196"."168"."0"."1"}....
source
share