I have a strange problem when adding a value to a String array, which later is involved in sorting the array using a hash map. I have an XFR900a file name, and part of XFR900 is added to the array using the following code:
private ArrayList<String> Types = new ArrayList<String>(); ... Types.add(name.substring(0,(name.length() - 1)); System.out.println(name.substring(0,(name.length() - 1));
I even print a line that gives "XFR900", however subsequently sorting the array behaves differently when I use the following code:
Types.add("XFR900"); System.out.println(name.substring(0,(name.length() - 1));
which is just a part of a substring made by hand, very confusing.
Are there any good alternatives to substring since there should be some odd character without ascii?
Phil
UPDATE
Thanks for your comments. Here are some of the code that compares the string later;
for (int i=0;i< matchedArray.size();i++){ //run through the arrays if (last == matchedArray.get(i)) { //add arrays to a data array ArrayList data = new ArrayList(); data.add(matchedArray1.get(i)); data.add(matchedArray2.get(i)); data.add(matchedArray3.get(i)); data.add(matchedArray4.get(i)); data.add(matchedArray5.get(i)); //put into hash map map.put(matchedArray.get(i), data); } else { //TODO System.out.println("DO NOT MATCH :" + last + "-" + matchedArray.get(i));
As you can see, I added the System.out.println test ("DO NOT SHOULD" ... and below - this is some kind of conclusion;
DON'T FOLLOW: FR99-XFR900 DON'T CONNECT: XFR900-XFR900
I run a substring for the XFR900a file name only. The problem is that for the test string to be printed last! = MatchedArray.get (i), however they will be the same when printed on the display.
Phil
source share