Could someone tell me why this method with split()
does not return the array correctly? Thanks
My intention is to send a String to the method that would be an ip and that the method returns that IP in an array of Strings.
public class hola {
public String[] metoth2 (String a) {
System.out.println("Ip obtenida");
System.out.println(a);
String ip[] = a.split(".");
System.out.println("Method2Array");
for (int i = 0; i < ip.length; i++) {
System.out.println(ip[i]);
}
return ip;
}
Main Class:
public class Main {
public static void main(String[] args) {
Hola text = new Hola();
String ipS="192.168.12.12";
String ip[];
ip=text.metoth2(ipS);
System.out.println("Printamos ip");
for (int i = 0; i < ip.length; i++) {
System.out.print(ip[i]);
}
}
}