Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Compare Just Created ArrayList to the one before

    Hi,

    I am having trouble figuring out how to compare each individual value of the ArrayList. I do this by assigning an empty ArrayList before the ArrayList I am about fill in but for some reason it fills both at the same time when I run the method. Do any of you have an idea why? Note: this code is not doing comparison but I can't fill them right in the first place to attempt to do comparison.

    Code:
       
       List<Long> StationsArrayListG7 = new ArrayList<>();
        List<Long> StationsArrayListG7a = new ArrayList<>();
    
    
    public void GetApplicationSpecificUserStats(MBeanServerConnection serverConnectionName) {
    
       StationsArrayListG7a = StationsArrayListG7; 
         
       String attrName = "current";   
       
       for(String stringName : gSelectedApplicationsFromFile) {
                   
             try {
                   String connectsName = "WowzaMediaServerPro:vHosts=VHosts,vHostName=_defaultVHost_,"
                                + "applications=Applications,applicationName=" + stringName + ",name=Connections";       
                       
                   ObjectName connectsObjName = new ObjectName(connectsName);
                   
                   try {
                   Long valueObj = (Long)serverConnectionName.getAttribute(connectsObjName, attrName);
    
                   valueX = valueObj;        
                   StationsArrayListG7.add(valueX);        
                   
               } catch (MBeanException ex) {
                   Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
               } catch (AttributeNotFoundException ex) {
                   Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
               } catch (InstanceNotFoundException ex) {
                   Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
               } catch (ReflectionException ex) {
                   Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
               } catch (IOException ex) {
                   Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
                   System.out.println("IOException Error has occured!");
               }
               }           
    
               catch (MalformedObjectNameException ex) {
                   Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
               }  
            
       }  
       
       
       }
    When I do it with individual variable instead of array it works fine. I can't figure it out if I am doing it right assigning array StationsArrayListG7a = StationsArrayListG7;. I tried copy and stuff like that but it kept giving me null.

    Thanks in advance.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That's exactly why they are the same. You are assigning StationsArrayListG7a the value of StationsArrayListG7, and then assigning StationsArrayListG7 items. Both StationsArrayListG7a and stationsArrayListG7 point at the same object, so they both retrieve the same results. Remove this assignment StationsArrayListG7a = StationsArrayListG7;, and they will point at the same list. I assume that your generic instantiation is of type Long as well; that will throw a compilation failure otherwise.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •