Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2012, 09:46 AM   PM User | #1
martyb
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
martyb is an unknown quantity at this point
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.
martyb is offline   Reply With Quote
Old 11-13-2012, 01:11 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:09 AM.


Advertisement
Log in to turn off these ads.