Help comparing two ArrayList initializations instructions.

I found these two methods to initialize ArrayList on a single row in a 3 years old topic here in this forum... so I open a new thread to ask you what you think is the best method I could use. Thank you!
    private static ArrayList<String> strSearchs = new ArrayList<String>(){{add(" state changed from Full to ");}};
    private static ArrayList<String> strSearchs2 = (ArrayList<String>)Arrays.asList(" state changed from Full to ");PS: note that original suggestions was for "List" objects, so I had to add a cast to "ArrayList" in the second instruction.

Pratically I have such objects which get a String (we can call it "*strOrig*") in the constructor. As result it parse the String, and store all parsed informations in object's variables\attributes.
Obviously the String is checked to control if it fits some parameters before parsing starts. The static ArrayList contains further requisites (Strings which have to "match" with "*strOrig*" content to confirm it is valid) which are chosen by "the user" (I mean who implements these kind of classes).
It mean that I need to make the ArrayList modificable (both substituted by another ArrayList variable, or adding, changing and/or removing content for the existing one). I made it static, so it will not create a new ArrayList for every instantiate object.
So if List can't support add and similar, I think it's not my case. :-S
Maybe I could instantiate the ArrayList in an AbstractList object, so also Vector could also be used bye "the user"... but this is not very related.
So maybe private static AbstractList<String> strSearchs = new ArrayList<String>(Arrays.asList(" state changed from Full to ")); is my case...
Do you agree with me?
WalterLaan wrote:
ThePatcha wrote:
The variable is not intended to be Final, it can be modified via static methods, but I need it's static (so unique for every object instantiated) and it starts with a defaul value already inside.static means the opposite: it is the same for all instances, not unique per instance.My fault: I meant "it's always the same for all instanced objects". I used "unique" instead of "always the same", sorry.
Edited by: ThePatcha on Feb 2, 2010 6:45 AM

Similar Messages

  • HELP : Comparing two programs(DEV & PROD)

    Hi,
    I want to compare two programs one from dev and other from prod and check whether it is identical or not....the number of programs are in thousands.....so is there any FM or program so that i can automate it.....plz help!!

    Hi Ajay,
    i have solution for ur problem.
    1. Go to program -> utilities-. version-> versiopn management.
    2.u arrive at new screen.
    3.type /h to make debuggin on.
    4. now click any push button for comparison..
    5.in field textbox of debbuger , type 'SY-UCOMM' to get the ok_code for that push-button.
    6.once u get the ok_code , u can use
    'CALL TRANSACTION 'SE38' USING BDC_DATA '.
    7.To get more details on such kind of abaP statement , select that statement and press F1 , you wud get reference example out at bottm..
    8. refere to that along with also check out for screen no , prohram name , ok_code , which are needed for that transaction.
    regards
    Note: reward points if useful

  • Problem comparing two ArrayLists, elements must match, order not important.

    Hello,
    I am new to Java and my assignment is:
    Write a method for the Purse class - public boolean sameCoins(Purse other), that checks whether the other purse has the same coins, perhaps in a different order.
    For example, the purses:
    *Purse[Quarter,Dime,Nickel,Dime]*
    and
    *Purse [Nickel,Dime,Dime,Quarter]*
    should be considered equal.
    You will probably need one or more helper methods.
    I was able to make a method to check if the purses match(sameContents), but I have not been able to check if they match just based on elements(sameCoins). We are not using Collections.
    Below is my Purse Class:
    import java.util.ArrayList;
    public class Purse {
        private ArrayList<String> coins;
        public Purse() {
            coins = new ArrayList<String>();
        public void addCoin(String coinName) {
            coins.add(coinName);
        public String toString() {
            String text = "Purse[ ";
            for (String a : coins)
                text += a;
            text += "]";
            return text;
        public boolean sameContents(Purse other) {
            boolean content = false;
            if (other.coins.equals(coins))
                content = true;
            return content;
        public boolean sameCoins(Purse other){
            boolean samecoins = true;
            for(String a: coins)
                for(String b: other.coins)
                    if (a.contains(b))
                        samecoins = true;
                    else
                        samecoins=false;
            return samecoins;
    }Any help would be appreciated.

    tipalm wrote:
    Well then my prof cant hold it against me can he!He sure can, if he wants to. I'll bet you 30 duke stars that if you hand in the program as-is and try to argue for using the Collections framework, he's going to say "I meant you couldn't use any of the static methods in the Collections framework, the whole point of the assignment was to work through the logic of iterating through the Lists" But hey, it's not my assignment, so good luck!
    Edit- I'm not saying that using the Collections framework (and its myriad static methods) is bad in any way. It's actually what you should use, assuming there are no academic "but don't use this shortcut" rules being applied. I just doubt that's your case here. I'd recommend looking into how the Collections framework works, and then implement your own algorithm based on that.
    Edited by: kevinaworkman on Oct 29, 2009 10:13 AM

  • Automating the process of comparing two PDF file with the help of QTP(Automation Testing Tool)

    Can anybody help me with comparing the two pdf files with the help of QTP.I have Adobe Acrobat installed on my system and i have access to the API.
    Thanks,
    Varun Saini

    I want to find out more about QTP and API. Maybe that is what I want to compare two mechanical drawings for differences between them. (see “More than one pdf file in one window”. Is that what you are looking to do? 9Not necessarily mechanical drawings but some other pdf).

  • Can you help me compare two chars?

    I keep getting a 'cannt be dereferenced' error whenever I try compareing two chars. What exactly does this mean? Here's the code I'm useing:
    import java.io.*;
    public class Replace
       public static void main(String[] args)
          char let = 'h';
          char let2 = 'i';
          int temp = let.compareTo(let2);
    }

    Thank you slappy for trying to make me leaern. In
    future, try to give a little background to wwhat your
    explaining. As you can see, I was useing character
    methods on a char, and your reply just plain confused
    me!Sir,
    I know it confused you. But I did say HINT. And I did say char and Character and I was hoping that would twig. For your future reference in Java pimitives are lower case while Class Names Begin With A Capital Letter.
    Well good luck.
    Sincerely,
    Slappy

  • How to get the intersection of two arraylist containing user defined obj??

    How to get the intersection of two arraylist containing user defined obj??
    I can easily get the intersection of two array list which containing some simple class(Integer, String). But how to get the intersection of two arrayList which contain user defined object?
    Here is the sample code..I can not run this out...anybody can help me? thank you very much..
    The correct result should be like this:
    2
    2
    but I can only get this:
    2
    0
    import java.util.*;
    public class testRetain{
         public static void main(String[] args){
              ArrayList a = new ArrayList();
              ArrayList b = new ArrayList();
              a.add( new dog(1,2,2) );
              a.add( new dog(1,2,1) );
    System.out.println(a.size() );
              b.add( new dog(1,2,2) );
              a.retainAll(b);
    System.out.println(a.size() );
    class dog implements Comparable{     
         int head;
         int arms;
         int legs;
         dog(int head, int arms, int legs){
              this.head = head;
              this.arms = arms;
              this.legs = legs;
         public int compareTo(Object o){
              if ( ((dog)o).head > this.head )
                   return -1;
              else if ( ((dog)o).head < this.head )
                   return 1;
              else
                   return 0;
    }

    @Op. Your classes should override equals and hashCode
    Kaj

  • Performance issues comparing two vectors

    I need some advice on what is the fastest way to compare two vectors. My question is all about performance;
    I have two vectors one(Vect A) of which has more than 20000 string values and the other Vector B would hold typically around 200 strings.I compare them both to find out if Vector B has values in Vector A and remove those.
    I iterate thro each element in a loop from the smaller to the bigger vector comparing element by element.But it takes a long time.
    Is there any quick way to do this comparison and can I use contains/compare methods instead of iterating thro the vectors.will it speeden up things
    Arn

    first of all, you should probably examine your collection choice and make sure that java.util.Vector is your best option (assumming you can change the class). Do not use a Hashtable as the previous poster suggested- it doesn't sound like you have a key/value type relationship in your elements, making a Map implementation superflous. Will there be duplicate elements in either Collection? If you will not have duplicate elements, you should probably use a Set collection instead of a List. Does your collection have to be thread-safe? If not, one of the unsynchronized collections should give you better performance (e.g. ArrayList should be quicker then Vector). For the best possible performance, you could use an ordered collection and write your own comparator, so that it does not iterate beyond what ever element assurres that there is no match (i.e. if the first element is "fred" in an ordered collection, you know there will be no match for "adam"). Sun has some good tutorials on the java.util.Collection package that will help you understand the benefit of each implemenation...
    although, and I suppose this is neither here nor there, I wouldn't use java objects to sort through 20K string items- sounds like storing them in a database might be superior. Take care.

  • Compare two strings for partial or full match

    I have been trying to figure out away of comparing two strings.
    I can get the full string matching to successfully work but am struggling on how to get partial eg wildcard search working.
    say I had names like paul Duncan, George Morrison.
    I have split them up so its now paul , duncan i then use the users entered string to compare it against the name name to see if it matches anything in the first name or the last name if it does i added it to an arraylist.
    however i have tried t use a indexof as i believe this looks for similarity (Substring matches?) but it always returns -1.
    Could anyone possibly direct me to a method that will allow me to use partial text string to match it against stored user names.
    eg user enters pa
    I would return anything that would contain pa
    thanks for any help

    thank you for the reply
    Sorry I forgot to put in the code.
    This is a reduced down version including the read in from a text file as well as the index of if statement and the adding of it to an array list.
    public class FindContact {
    String res;
    /** Creates a new instance of FindContact */
    public FindContact() {
    public Object[] FindAUser(String passSearch) {
    System.out.println("getting here");
    ArrayList found = new ArrayList();
    String patternStr = ",";
    int j, i = 0;
    try {
    BufferedReader in = new BufferedReader(new FileReader("H:\\out.txt"));
    String str;
    while ((str = in.readLine()) != null) {
    String[] fields = str.split(patternStr);
    //for(j=0;j < fields.length;j++) {
    if (fields.length != 0) {
    if (passSearch.indexOf(fields[0])!=-1 || passSearch.indexOf(fields[1])!=-1) {
    found.add(str);
    System.out.println("ENDDDDDDDD value ");
    in.close();
    } catch (IOException e) {
    System.out.println(e.toString());
    Object[] foundResult = new Object[found.size()];
    foundResult = found.toArray();
    if (foundResult.length >= 0) {
    System.out.println(foundResult.length);
    return foundResult;
    Hope that helps as it has confused me and am not sure why it is not returning a value.
    Should I maybe use the contain method instead to search for the user inputted string?

  • Compare two similar objects

    Do you know about any possible Java bugs with JDK update?
    In my case, my code stopped working.
    Here is what I have. There are two similar objects, but Object 1 has key, and Object 2 (same as Object 1) has no key. I need to compare both, and if they are equal, I need Object 1 to assign key to Object 2.
    It worked before. How I can get around.
    Please help me if you can.
    Respectfully,
    Alex

    Let me change the question:
    "Can we compare two objects one with key and another one without key? How?

  • Compare two Java Objects without Comparable / Comparator

    Hi Friends,
    I would like to compare two java objects (lots o attributes) without using Comparable / Comparator.
    Any suggestion/sample code would be helpful.
    Thanks,
    Sachin

    I suppose you could design another feature to compare Objects... but that would involve a design process, so asking for sample code is definitely premature. And as EJP says, what would be the point?
    At least that's what I would answer if this was one of those stupid interview questions.

  • How can i compare two excel files with different no. of records.

    Hi
    I am on to a small project that involves us to compare two excel files. i am able to do it but am struck up at a point. When i compare 2 different .csv files with different no. of lines i am only able to compare upto a point till when the number of lines is same in both the files.
    Eg. if source file has 8 lines and target file has 12 lines. The difference is displayed only till 8 lines and the remaining 4 lines in source lines are not shown.
    Can you help me in displaying those extra 4 lines in source file. I am attaching my code snippet below..
    while (((strLine = br.readLine()) != null) && ((strLine1 = br1.readLine())) != null)
                     String delims = "[;,\t,,,|]";
                    String[] tokens = strLine.split(delims);
                    String[] tokens1 = strLine1.split(delims);
                   if (tokens.length > tokens1.length)
                    for (int i = 0; i < tokens.length; i++) {
                        try {
                            if (!tokens.equals(tokens1[i])) {
    System.out.println(tokens[i] + "<----->" + tokens1[i]);
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + tokens1[i]);
    out.println();
    sno++;
    } catch (Exception exception)
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + "");
    out.println();
    Thanks & Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    A CSV file is not an Excel file.
    But apart from that your logic makes no sense.
    If the 2 files are of different sizes the files are different by definition, so further comparison isn't needed, you're done.
    If you want to compare individual records, you need to compare all records from one file with all records from the other, unless the order of records is important in which case your current system might work.
    That system however is overly complicated for comparing CSV files.
    As you assume a single record per line, and if one can assume those records to have identical layout (so no leading or trailing whitespace in or between columns in one file that's not in the other) comparing records is simply a matter of comparing the entire lines.

  • Functinality to compare two material price with reference to BOM in CO

    Hi All,
    Is there is any functionality in Controlling which can compare the costing for two FERT materials.
    or
    is there is  any functionality where we can compare two material price with reference to BOM in controlling
    Please help me to compare the material price with reference to BOM
    Regards
    nandu

    Hi,
    You can use this report to compare two itemizations. The report compares the characteristics item number, item category, cost element, resource, material, cost center, plant/work center, cost center/activity type, operation number, BOM item, assembly indicator, and cost component.
    You can access this report as follows:
    Accounting ® Controlling ® Product Cost Controlling ® Product Cost Planning ® Material Costing ® Cost Estimate with Quantity Structure or Cost Estimate Without Quantity Structure ® Compare
    or
    Accounting ® Controlling ® Product Cost Controlling ® Product Cost Planning ® Information System ® Object Comparisons ® For Material ® Itemization Comparison.
    For Detail Please reffer following link:
    http://help.sap.com/saphelp_46c/helpdata/en/56/abd108f1a611d28a950000e8214595/content.htm
    Thanks and Regards
    Binoj M D

  • How to compare two excel reports and find the difference in BI Publisher

    Hi All,
    I have a requirement that needs to compare two excel reports in XML Publisher 5.6.2. or BI publisher 10.1.3.4
    If anybody has an idea about this pls help us.
    Thanks,

    Since our customer wants to have this comparison only with BI reports....here is the scenario how the comparison should be..
    Now,we have a parameters called Customer name and version id. Version id list will be refreshed based on the customer selection.
    User can generate the report based on the selected customer name and version id. These data are fetch from the oracle database and we are using Data Template in the BI Publisher.
    Now the requirement is customer wants to compare two version id data. for example, v1.2 and v1.3
    Now they wanna to see both the reports while generating in the same work sheet, like, v1.2report should display in the left side and the v1.3report has to display in the right hand side of the same work sheet.
    Now...If there is any addition happened in v1.3 report,then that cell/data should display as a green color in that report.
    If any deletion happened in v1.3report then that should be in the red color.
    If any modification happened in v1.3 then that should be in the yellow color.
    If there is no difference then that should display as it is.
    the thing is that, the both the reports (v1.2 and v1.3)should display side by side in the same worksheet with the format and everything........only the difference should be highlighted.
    Template is same for both the reports..
    To display the data for both versions i think i can generate the template side by side of both in the same worksheet.
    Now, My question is how to find the difference of data in the RTF Template for both the versions
    Can anybody assist me?
    Thanks,
    Edited by: user753355 on Jun 9, 2009 12:03 AM
    Edited by: user753355 on Jun 9, 2009 12:06 AM
    Edited by: user753355 on Jun 9, 2009 12:16 AM
    Edited by: user753355 on Jun 10, 2009 3:59 AM

  • Compare two pdf files using adobe acrobat through command line

    Does anyone know how to compare two pdf files using adobe acrobat through command line. I want to do this via command line because we want to compare hundreds of file every day through some automated windows tasks.
    If command line option is not available in acrobat, then is it feasible to make use of acrobat javascript API to do this task?
    Any kind of help will be greatly.

    Command-line: Not possible.
    JavaScript: Possible, but very limited. Basically the only thing you can do is simulate clicking the Compare Documents button. The rest has to be done manually.
    However, it *might* be possible to automate this process a bit more using a plugin. Ask over at the Acrobat SDK forum for more information...

  • How to change the color of letters instead of highlight the text when compare two documents

    Hello!!
    I have the Adobe Acrobat 9 Pro (Versión 9.0.0) and I need to compare two documents, but I want to show the diferences changing  the color of letters instead of highlight the text with any color. My boss tell me that other Acrobat version have this option, but I couldn't find it in this version.
    Could you help me on this topic??
    Thanks

    Hello!!
    I have the Adobe Acrobat 9 Pro (Versión 9.0.0) and I need to compare two documents, but I want to show the diferences changing  the color of letters instead of highlight the text with any color. My boss tell me that other Acrobat version have this option, but I couldn't find it in this version.
    Could you help me on this topic??
    Thanks

Maybe you are looking for

  • Printer won't print black

    My printer was printing one day just fine, then the next day black was not printing, would instead print a faint blue. I put in a new cartridge and aligned, but still doing the same thing. I have gone through the printer support and done the printhea

  • How to stop Internet Explorer upgrade to IE 10 & IE 11

    Dear All, How to stop Internet Explorer upgrade to IE 10 & IE 11  In our environment we have around 300 workstations.I need to stop all of the machine users from manually downloading and installing IE.Also how do it stop the IE from updating using Gr

  • I'm trying to install iTunes on my Dell PC.

    I AGREE on the licensing page and, then, nothing happens

  • Making the fields grey in a sap screeen

    Hi all In CKECP transaction, while hitting the display button, the next screen appears with estimae details. While pressing the 'show item view', a subscreen with the estimate details appears. Now the requirement is to make the 'Total Price' and Tota

  • Cube usuage in SAP BW

    Dear All, I would like to have a report or view of the cubes that are being used in one of my BW system. Basically the statistics is required like for example how many times a query hits the cube. Do we have any standard procedure available to take c