Optimize Memory Java String Array
Welcome to Stack Review, it seems me there is no much space for improvement, just some little tips:
class Ipv4Address {
    String ipAddress;
    boolean state;
    List&lt;Ipv4Address&gt; connections;
   
    //setters and getters
}

Probably you included your Ipv4Address class inside the NumberOfDevices class file but for a cleaner code better create a Ipv4Address class file separated. If you have defined setters and getters, you can encapsulate fields into the class using the private access modifier like below:
public class Ipv4Address {
    private String ipAddress;
    private boolean state;
    private List&lt;Ipv4Address&gt; connections;

    public Ipv4Address(String ipAddress) {
        this.ipAddress = ipAddress;
        this.state = false;
        this.connections = new ArrayList&lt;&gt;();
    }
    
    //getters and setters
}

No much to say about NumberOfDevices; in its numberOfDevices method you have the following code :
public static int[] numberOfDevices(String[][] connections, String [] toggleIps) {
    int count =0;
    int [] result = new int[toggleIps.length];
    if(connections.length&gt;0) { // already a given contaraint that the length of toggle IPs is &gt;=1
    
    
       Map&lt;String,Ipv4Address&gt; ip = new HashMap&lt;&gt;();
       for(int i=0; i&lt;connections.length; i++) {
          Ipv4Address ip1, ip2;
                    
          if(!ip.containsKey(connections[i][0])) {
            ip.put(connections[i][0], new Ipv4Address(connections[i][0]));                  
          }
          if(!ip.containsKey(connections[i][1])) {
            ip.put(connections[i][1], new Ipv4Address(connections[i][1]));                  
          }
                    
          ip1=ip.get(connections[i][0]);
          ip2=ip.get(connections[i][1]);
                    
          ip1.addConnection(ip2);
          ip2.addConnection(ip1);
    
     }

      //other lines
}

You can rewrite this part of your method using a foreach construct like below:
public static int[] numberOfDevices(String[][] connections, String[] toggleIps) {
    int[] result = new int[toggleIps.length];

    if (connections.length == 0) { return result; }

    Map&lt;String, Ipv4Address&gt; map = new HashMap&lt;&gt;();

    for (String[] connection : connections) {

        for (String c : connection) {

            if (!map.containsKey(c)) {
                map.put(c, new Ipv4Address(c));
            }
        }

        Ipv4Address ip1 = map.get(connection[0]);
        Ipv4Address ip2 = map.get(connection[1]);
        ip1.addConnection(ip2);
        ip2.addConnection(ip1);
   }

   //other lines
}