[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sorting ArrayList Objects.

Posted on 2008-11-10
55
Medium Priority
?
544 Views
Last Modified: 2012-08-13
Hi all, this question has been asked before but I am not sure a working example was ever posted. The below code example works when using the first string array and bombs using the second string array. Can anyone please help?
Thanks!
import java.util.*;
 
public class SortObjects
{     
     public static void main(String s[])
     { //The first string works and the second one bombs. The difference is the 5th element
		//String t[] = { "1", "19", "2", "3pt1", "4", "5pt1", "6pt2", "7pt3", "7pt3" };
		String t[] = { "1", "19", "2", "3pt1", "3", "5pt1", "6pt2", "7pt3", "7pt3" };
						
 
        // The input is a String array. Make that an ArrayList:
        List inputList = new ArrayList(Arrays.asList(t));          // replace "t" by "s" for using the command line arguments
        
        List l = sort(inputList);
          
        System.out.println("\nStrings sorted List ...");
        for(int i = 0; i < l.size(); i++) 
            System.out.println((String)l.get(i)); 
    }
     
    public static List sort(List list) {
          Collections.sort(list, new Comparator() {
 
            public int compare(Object o1, Object o2) {
                 String s1 = (String)o1;
                 String s2 = (String)o2;
 
                 String integer1[] = s1.split("[^0-9]");      // <<<<<  changed
                 String integer2[] = s2.split("[^0-9]");      // <<<<<  changed
                 String chars1[] = s1.split("[0-9]+");         // <<<<<  changed
                 String chars2[] = s2.split("[0-9]+");         // <<<<<  changed
 
                 Integer i1 = new Integer( Integer.parseInt(integer1[0]) );
                 Integer i2 = new Integer( Integer.parseInt(integer2[0]) );
 
                 if (i1.equals(i2))
                    return chars1[1].compareTo(chars2[1]);
                  else
                     return i1.compareTo(i2);
            }
        });
        return list; 
    }
}

Open in new window

0
Comment
Question by:OggieOne
  • 25
  • 20
  • 10
55 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22927793
Think it is bombing because 3 equals 3 from 3pt1 then you are dropping into this code:
return chars1[1].compareTo(chars2[1]);

For 3, there is no chars2[1].  It works with other string as there are no values that satisfy condition 1 where values equal and the values aren't the exact same string.

As a question, why are you not just comparing these as strings?  If you use:

List<String> list = new ArrayList<String>(Arrays.asList(t));

This should sort without need of a special comparator object as Strings can be compared already.
0
 

Author Comment

by:OggieOne
ID: 22929764
I can't compare everything as strings as the data that I need to sort are combinations of numbers and letters. For example I need to sort 1 , 2 , 3 , 3pt1 , 3pt2 , 4 , 4pt1 , 5pt .... etc..Make sense?

Thanks.
0
 

Author Comment

by:OggieOne
ID: 22929777
Sorry..I should add this. Once you get to say 10pt2 the order then becomes

1, 10pt2, 2, 3, 4 etc...when 10pt2 should be at the bottom of the list and not after 1.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22929887
Makes sense.  Did you see my comment on what you should look at in code.  The string comparison was just a side suggestion, I did give an answer to your question above too.

Let me know what issues you are having after looking into that.

Regards,
Kevin
0
 

Author Comment

by:OggieOne
ID: 22930173
Yes I did see where it bombs. I guess my real question would be then how do I fix that? Do I need to start testing the length and if it's not there return --> return chars1[1]
I guess this whole sorting thing is a bit beyond my comprehension.
Thanks for your help.
0
 

Author Comment

by:OggieOne
ID: 22930501
It seems to work now and I get the same sorted results regardless of wether I return a 0 or a -1 when there is no chars2[1]. For example this *appears* to sort correctly now.

              if (i1.equals(i2)){
                    try{
                        return chars1[1].compareTo(chars2[1]);
                    }
                    catch(Exception e){
        return 0;
                    }
              }
              else{
                    return i1.compareTo(i2);
              }
                    
0
 

Author Comment

by:OggieOne
ID: 22932002
Help! It still doesn't work..even though I said it did. Now if you pass a string that doesn't start with a number it throws a NumberFormatException even though I see the above if statement return a 0. Any ideas?

By adding the following to the string array -> pt2

Thanks!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22932485
You  can take this approach to get the exact (i guess) result you need:

http://technojeeves.com/joomla/index.php/free/64-java-custom-comparator-with-generics
0
 

Author Comment

by:OggieOne
ID: 22932671
Thanks for the post! Perhaps I should eloborate on what I am doing. The values for the string come from a database that has no restriction on what they can enter. This case is actually movie/tv scenes.
So users can enter Scene 1ptA or 1pt2 or A1 or whatever they want (usually guided by a movie script).
I see your sample has the hardcoded "pt" but sadly I won't know what the actual letters are. The sort that I have only blows up when the scene doesn't start with a number. I currently *hacked* it to pre-pend a ZERO if it doesn't start with a number but that is a bit of a hack...ok maybe more than a bit :-)

Is there a better way to do this?

Thanks,
Doug
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22933047
The best way is to constrain input, otherwise you have a 'garbage in, garbage out' scenario. There's no such thing as code that can cope with arbitrary input
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22933197
That is because the whole code above is based on values starting with a number:

Integer i1 = new Integer( Integer.parseInt(integer1[0]) );

This indicates that there will always be an integer to parse at index 0 of the array.

If you can't constrain the data, I would suggest you make this much simplier and check if the entire number is numeric and then sort as number otherwise sort as text and just decide which come first text or numbers.  You can probably go through to sort the text and numbers together as you are so that 10 and 10pt1 sort together; however, you will have to account for every single variation of the string the database can throw out.

For example what is stopping the db from sending pt10-12 and how would that sort with pt10-9.

Anyway, don't want to belabour this.
0
 

Author Comment

by:OggieOne
ID: 22933253
I wish I could constrain the input better but I think I can only recommend a certain format for best sorting results.
Thanks for all your help.
Doug
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22933313
Is it a web form?
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22933321
Understand and you are welcome.

Like I said, you seem comfortable with regular expressions, I would just check if the string is all numbers and then convert to integer and compare otherwise compare as string.  You can also return appropriate greater than or less than response based on how you want integers to sort with respect to text.

-1 means smaller
0 means equal
1 means greater
0
 

Author Comment

by:OggieOne
ID: 22933768
Yes the data is submitted via a webpage (form). I just can't restrict the users of my application as to what they say a movie scene number may be called. I have to let them say what it is (ie: mix of numbers and letters).
So the problem arises when the user enters a combination of letters and numbers, therefore I can't sort as a string or as a number.
I think the *hack* I have in place will have to do and I then recommend to the users that a scene should start with a number and NOT a letter.

Thanks,
Doug
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22934533
Using a drop down of scene numbers would do it would it not?
0
 

Author Comment

by:OggieOne
ID: 22936147
Nope, can't do that. All productions are different.....sadly.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22936164
I would agree with CEHJ on getting control of the source, but if you cannot here is an example of what I meant by sorting the text and numbers separately.

http://crossedlogic.blogspot.com/2008/11/java-custom-comparators-sorting-text.html

You can modify this to your liking as the implementation sorts numbers first, then text with numbers in front, then text (possibly withn numbers after first character(s)).  The code for the middle case may be used to sort everything intermingled as you desired ...
public static java.util.List<String> sort(java.util.List<String> list) {
		java.util.Collections.sort(list, new java.util.Comparator<String>() {
			/**
			 * Custom compare to sort numbers as numbers. Strings as strings,
			 * with numbers ordered before strings.
			 * 
			 * @param o1
			 * @param o2
			 * @return
			 */
			@Override
			public int compare(String o1, String o2) {
				boolean isFirstNumeric, isSecondNumeric;
 
				isFirstNumeric = o1.split("[^0-9]")[0].matches("\\d+");
				isSecondNumeric = o2.split("[^0-9]")[0].matches("\\d+");
 
				if (isFirstNumeric) {
					if (isSecondNumeric) {
						int intCompare = Integer.valueOf(o1.split("[^0-9]")[0])
								.compareTo(
										Integer.valueOf(o2.split("[^0-9]")[0]));
						if (intCompare == 0) {
							return o1.compareToIgnoreCase(o2);
						}
						return intCompare;
					} else {
						return -1; // numbers always smaller than letters
					}
				} else {
					if (isSecondNumeric) {
						return 1; // numbers always smaller than letters
					} else {
						return o1.compareToIgnoreCase(o2);
					}
				}
			}
 
		});
		return list;
	}

Open in new window

0
 

Author Comment

by:OggieOne
ID: 22936446
Thanks! I will try that first thing tomorrow! Your help is greatly appreciated (everyones).
0
 

Author Comment

by:OggieOne
ID: 22940811
OK here goes my first stupid question for the day..(how many am I allowed?)...
Here are my results from using the above sort.
7pt1
7pt10
7pt10
7pt12
7pt14
7pt4
7pt4
7pt5
7pt5
7pt5
7pt6
7pt6
7pt6
7pt7
7pt7
7pt8
7pt8

Can the sort be modified to sort the following so that they appear AFTER the 7pt8?

7pt10, 7pt10, 7pt12, 7pt14

The 7pt10 etc...should NOT be before 7pt4.

Is this possible?

Thanks Again!

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22940833
You obviously didn't run the code i posted ;-)
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22940878
It is possible, you are just asking for extra headaches as you don't have a standard format, so you will have to continual keep checking if a part is numeric.  I would just stop at the top level personally.

But you should be able to adjust the logic from what I gave you.

CEHJ, the point I think is that 'pt' is not necessarily part of the string.  Think that was just an example.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22940953
>>CEHJ, the point I think is that 'pt' is not necessarily part of the string.

I'm aware of that - yet it's come back and is being used again for some reason ;-)
0
 

Author Comment

by:OggieOne
ID: 22941070
CEHJ - which code are you referring to? The one with the hard coded "pt" in it?

And yes it is like I am begging for headaches. Sadly I have no choice and cannot stop people from entering whatever they want. This code is for television and movie scripts and people can call a scene all sorts of wonderful things. So it could end up Scene -> 7part1 or 7pt1 or 7ptA or 7pt1A.
As for "adjust the logic "..since I don't understand fully what you did I am not sure I am capable of adjusting the code...again sadly. Although that code woudn't comile as is. I got this error ->

The type new Comparator(){} must implement the inherited abstract method Comparator.compare(Object, Object)

So I added the method.
Thoughts?


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22941311
>>CEHJ - which code are you referring to? The one with the hard coded "pt" in it?

Yes, IOW the one that will work correctly with the example input you just posted
0
 

Author Comment

by:OggieOne
ID: 22941577
Yes you are correct CEHJ, I didn't run that code as the hard coded "pt" doesn't always apply it just happens to be what one of my users is entering.
Perhaps though I can use that and remove whatever the characters are before sorting.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22941672
>>I didn't run that code as the hard coded "pt" doesn't always apply it just happens to be what one of my users is entering.

Yes i know that it doesn't always apply, yet you *are* running it with the other code, that i didn't supply ...

>>Perhaps though I can use that and remove whatever the characters are before sorting.


Yes, for the middle, you can use the pattern "\D+" instead of "pt"
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22941713
Sorry

"\\D+"
0
 

Author Comment

by:OggieOne
ID: 22941815
OK I just tried that and I still get the following results.

sceneNumber = 7pt1
sceneNumber = 7pt10
sceneNumber = 7pt10
sceneNumber = 7pt12
sceneNumber = 7pt14
sceneNumber = 7pt4
sceneNumber = 7pt4
sceneNumber = 7pt5
sceneNumber = 7pt5
sceneNumber = 7pt5
sceneNumber = 7pt6
sceneNumber = 7pt6
sceneNumber = 7pt6
sceneNumber = 7pt7
sceneNumber = 7pt7
sceneNumber = 7pt8
sceneNumber = 7pt8

The code I ran is included and is from CEHJ (I switched the "pt" with the "\\D+"

Thanks,
Doug

	public static void sort(List list) 
	{        
		Collections.sort(list, new Comparator() {
				
			public int compare(Object o1, Object o2) {
				return compare( o1.toString() , o2.toString() );
			}			
 
			
			public int compare(String s1, String s2) {
				int result = 0;
				double val1;
				double val2;
				String[] temp1 = s1.split("\\D+");
				String[] temp2 = s2.split("\\D+");
				if (temp1.length > 1) {
					val1 = Double.parseDouble(
							new StringBuilder().append(temp1[0]).append('.').append(temp1[1]).toString());
				}
				else {
					val1 = Double.parseDouble(s1);
				}
				if (temp2.length > 1) {
					val2 = Double.parseDouble(new StringBuilder().append(temp2[0]).append('.').append(temp2[1]).toString());
				}
				else {
					val2 = Double.parseDouble(s2);
				}
				if (val1 > val2) {
					result = 1;
				}
				else if (val2 > val1) {
					result = -1;
				}
				else {
					result = 0;
				}
				return result;
				}
			}
		);}

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22941866
Yes, but that's *not* the code i wrote. Mine uses generics and does not have the method

compare(Object ....
0
 

Author Comment

by:OggieOne
ID: 22941913
I couldn't compile the code as supplied as I stated earlier. What was I supposed to do then?
I don't understand what you mean by "Mine uses generics". How would I implement that then?
I merely added the the method that it was complaining about.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22941984
CEHJ, he used your code with an additional compare method in it is all. ;)

BTW, if you split on "\\D+" instead of "pt" then you are splitting on the numbers instead of on the string as you were previously.  Think you want "[^\\D]+" or "[^0-9]+".  Maybe uppercase D means something different than lowercase d.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22942004
Use my code here http:#22936164 as a base which you got to compile and then just swap in CEHJ's implementation of sort().
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22942020
new java.util.Comparator<String> <-- the <String> part is using generic.  Comparator with <?> is raw type.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22942027
...meant Comparator *without* <?> is raw type by the way.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22942028
It's almost identical, but the differences will break it entirely. See below:
        public static void sort(List list) 
        {        
                Collections.sort(list, new Comparator<String>() {
                        
                        public int compare(String s1, String s2) {
                                int result = 0;
                                double val1;
                                double val2;
                                String[] temp1 = s1.split("\\D+");
                                String[] temp2 = s2.split("\\D+");
                                if (temp1.length > 1) {
                                        val1 = Double.parseDouble(
                                                        new StringBuilder().append(temp1[0]).append('.').append(temp1[1]).toString());
                                }
                                else {
                                        val1 = Double.parseDouble(s1);
                                }
                                if (temp2.length > 1) {
                                        val2 = Double.parseDouble(new StringBuilder().append(temp2[0]).append('.').append(temp2[1]).toString());
                                }
                                else {
                                        val2 = Double.parseDouble(s2);
                                }
                                if (val1 > val2) {
                                        result = 1;
                                }
                                else if (val2 > val1) {
                                        result = -1;
                                }
                                else {
                                        result = 0;
                                }
                                return result;
                                }
                        }
                );}

Open in new window

0
 

Author Comment

by:OggieOne
ID: 22942466
I am in over my head here as I do not know how I can get this to compile.
Collections.sort(list, new Comparator<String>()......

In both of your (CEHJ and mwvisa1) code examples you reference <String> and I cannot compile a class with that sort of declaration in it. What am I missing here?

Thanks,
Doug


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22942524
Sorry - for some reason i thought you were using >= 1.5 What version are you using?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22942610
If you're using < 1.5, just begin

                Collections.sort(list, new Comparator() {
                        
                        public int compare(Object o1, Object o2) {
                                int result = 0;
                                double val1;
                                double val2;
                                String s1 = (String)o1;
                                String s2 = (String)o2;
                                String[] temp1 = s1.split("\\D+");
                                String[] temp2 = s2.split("\\D+");

Open in new window

0
 

Author Comment

by:OggieOne
ID: 22942699
OK I am getting somewhere at least after switching JDK's. Here is the exact code that I am running (it is your code CEHJ). And the output is still not ordered as *we* expect.
sceneNumber = 7pt1
sceneNumber = 7pt10
sceneNumber = 7pt11
sceneNumber = 7pt12
sceneNumber = 7pt2
sceneNumber = 7pt3
sceneNumber = 7pt3
sceneNumber = 7pt5
sceneNumber = 7pt5
sceneNumber = 7pt6

Thoughts?
Thanks,
Doug

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
 
public class Sort3 {
	
	public static void main(String[] args){
		Sort3 sorter = new Sort3();
		try{
			sorter.run();
		}
		catch(Exception e){
			System.out.println("Error : " + e.toString() );
		}
	}
	
	private void run() throws Exception
	{
	    
	    String[] inputStringArray = { "7pt1", "7pt2", "7pt3", "7pt3", "7pt5", "7pt6", "7pt10", "7pt11", "7pt12", "7pt5" };
	    java.util.List<String> inputList = new java.util.ArrayList<String>(java.util.Arrays.asList(inputStringArray));	    
	    sort( inputList );
	    for ( int i = 0 ; i < inputList.size() ; i++ ){
	    	String sceneNumber = ( String ) inputList.get( i ) ;
	    	System.out.println("sceneNumber = " + sceneNumber );
	    }
	}
	
 
    public static void sort(List list) 
    {        
            Collections.sort(list, new Comparator<String>() {
                    
                    public int compare(String s1, String s2) {
                            int result = 0;
                            double val1;
                            double val2;
                            String[] temp1 = s1.split("\\D+");
                            String[] temp2 = s2.split("\\D+");
                            if (temp1.length > 1) {
                                    val1 = Double.parseDouble(
                                                    new StringBuilder().append(temp1[0]).append('.').append(temp1[1]).toString());
                            }
                            else {
                                    val1 = Double.parseDouble(s1);
                            }
                            if (temp2.length > 1) {
                                    val2 = Double.parseDouble(new StringBuilder().append(temp2[0]).append('.').append(temp2[1]).toString());
                            }
                            else {
                                    val2 = Double.parseDouble(s2);
                            }
                            if (val1 > val2) {
                                    result = 1;
                            }
                            else if (val2 > val1) {
                                    result = -1;
                            }
                            else {
                                    result = 0;
                            }
                            return result;
                            }
                    }
            );}
	
}

Open in new window

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 22943757
So sorry - silly me. I wasn't taking into account a part number > 9 in my previous code. The following class will work. I've made a standalone Comparator to get rid of the ugly and error-prone anonymous inner class:
    static class SceneComparer implements Comparator<String> {
        private String[] buf1 = new String[2];
        private String[] buf2 = new String[2];
        private int result = Integer.MIN_VALUE;
        public int compare(String s1, String s2) {
            String[] temp1 = s1.split("\\D+");
            String[] temp2 = s2.split("\\D+");
 
            if (temp1.length == 1) {
                buf1[0] = temp1[0];
                buf1[1] = "1";
            }             else if (temp1.length == 2) {
                System.arraycopy(temp1, 0, buf1, 0, buf1.length);             }
            if (temp2.length == 1) {
                buf2[0] = temp2[0];
                buf2[1] = "1";
            }
            else if (temp2.length == 2) {
                System.arraycopy(temp2, 0, buf2, 0, buf2.length);
            }
            result = Integer.parseInt(temp1[0]) - Integer.parseInt(temp2[0]);
            if (result == 0) {
                result = Integer.parseInt(temp1[1]) - Integer.parseInt(temp2[1]);
            }
            return result;
        }
    }

Open in new window

0
 

Author Comment

by:OggieOne
ID: 22944144
Thanks for the code! I am trying to use it but I am at a loss as to how to invoke it? Sorry for my ignorance!
I was doing it like this before (see code snippet). How would I get my list into the new class?

Thanks!
Doug

OLD WAY...
    public static void sort(List list) 
    {        
     Collections.sort(list, new Comparator<String>() {
              public int compare(String s1, String s2) {
                            int result = 0;
etc.....

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22944221
New way:
Collections.sort(list, new SceneComparer());

Open in new window

0
 

Author Comment

by:OggieOne
ID: 22944267
BRILLIANT!
Thank you soooo much!!

sceneNumber = 7pt1
sceneNumber = 7pt2
sceneNumber = 7pt3
sceneNumber = 7pt3
sceneNumber = 7pt5
sceneNumber = 7pt5
sceneNumber = 7pt6
sceneNumber = 7pt10
sceneNumber = 7pt11
sceneNumber = 7pt12
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22944312
:-)
0
 

Author Comment

by:OggieOne
ID: 22944604
I spoke too soon.....now that I use my real data from the database I get the following error ( Error : java.lang.ArrayIndexOutOfBoundsException: 1 ).
Here is a listing of the data that gets passed to the sort. Any ideas? I wrapped single quotes around the value to make sure there were not any spaces.
See anything that would break it?

Thoughts?

Thanks!

myScenes[i] = '10'
myScenes[i] = '10'
myScenes[i] = '10'
myScenes[i] = '10Apt1'
myScenes[i] = '10Apt1'
myScenes[i] = '10Apt1'
myScenes[i] = '11'
myScenes[i] = '11'
myScenes[i] = '12'
myScenes[i] = '12'
myScenes[i] = '13'
myScenes[i] = '13'
myScenes[i] = '14'
myScenes[i] = '14'
myScenes[i] = '15pt1'
myScenes[i] = '15pt1'
myScenes[i] = '16'
myScenes[i] = '16'
myScenes[i] = '16'
myScenes[i] = '16'
myScenes[i] = '16'
myScenes[i] = '16'
myScenes[i] = '17'
myScenes[i] = '17'
myScenes[i] = '17'
myScenes[i] = '17'
myScenes[i] = '17'
myScenes[i] = '17'
myScenes[i] = '17'
myScenes[i] = '18'
myScenes[i] = '18'
myScenes[i] = '19'
myScenes[i] = '19'
myScenes[i] = '19'
myScenes[i] = '19'
myScenes[i] = '19'
myScenes[i] = '19'
myScenes[i] = '20pt1'
myScenes[i] = '20pt1'
myScenes[i] = '20pt1'
myScenes[i] = '20pt3'
myScenes[i] = '20pt3'
myScenes[i] = '21'
myScenes[i] = '21'
myScenes[i] = '21'
myScenes[i] = '22'
myScenes[i] = '23'
myScenes[i] = '24'
myScenes[i] = '24'
myScenes[i] = '24'
myScenes[i] = '24'
myScenes[i] = '25pt1'
myScenes[i] = '25pt1'
myScenes[i] = '25pt1'
myScenes[i] = '25pt1'
myScenes[i] = '25pt1'
myScenes[i] = '26'
myScenes[i] = '26'
myScenes[i] = '27pt1'
myScenes[i] = '27pt1'
myScenes[i] = '27pt1'
myScenes[i] = '29pt1'
myScenes[i] = '29pt1'
myScenes[i] = '29pt1'
myScenes[i] = '29pt2'
myScenes[i] = '29pt2'
myScenes[i] = '29pt2'
myScenes[i] = '29pt3'
myScenes[i] = '29pt3'
myScenes[i] = '29pt3'
myScenes[i] = '29pt4'
myScenes[i] = '29pt4'
myScenes[i] = '29pt4'
myScenes[i] = '29pt5'
myScenes[i] = '29pt5'
myScenes[i] = '29pt5'
myScenes[i] = '29pt6'
myScenes[i] = '2pt1'
myScenes[i] = '2pt1'
myScenes[i] = '2pt1'
myScenes[i] = '3'
myScenes[i] = '3'
myScenes[i] = '30pt1'
myScenes[i] = '31pt1'
myScenes[i] = '31pt1'
myScenes[i] = '31pt1'
myScenes[i] = '31pt1'
myScenes[i] = '31pt1'
myScenes[i] = '31pt1'
myScenes[i] = '31pt1'
myScenes[i] = '31pt2'
myScenes[i] = '31pt2'
myScenes[i] = '31pt3'
myScenes[i] = '32'
myScenes[i] = '32'
myScenes[i] = '32'
myScenes[i] = '32'
myScenes[i] = '33'
myScenes[i] = '33'
myScenes[i] = '34'
myScenes[i] = '34'
myScenes[i] = '35'
myScenes[i] = '35'
myScenes[i] = '35'
myScenes[i] = '36pt1'
myScenes[i] = '36pt1'
myScenes[i] = '36pt1'
myScenes[i] = '36pt1'
myScenes[i] = '36pt1'
myScenes[i] = '36pt1'
myScenes[i] = '36pt1'
myScenes[i] = '36pt1'
myScenes[i] = '36pt2'
myScenes[i] = '36pt3'
myScenes[i] = '36pt3'
myScenes[i] = '36pt3'
myScenes[i] = '36pt3'
myScenes[i] = '36pt3'
myScenes[i] = '36pt3'
myScenes[i] = '36pt3'
myScenes[i] = '36pt3'
myScenes[i] = '37pt1'
myScenes[i] = '37pt1'
myScenes[i] = '37pt1'
myScenes[i] = '37pt1'
myScenes[i] = '37pt1'
myScenes[i] = '37pt1'
myScenes[i] = '37pt2'
myScenes[i] = '37pt3'
myScenes[i] = '37pt3'
myScenes[i] = '37pt3'
myScenes[i] = '37pt3'
myScenes[i] = '37pt3'
myScenes[i] = '4pt1'
myScenes[i] = '4pt1'
myScenes[i] = '4pt1'
myScenes[i] = '5'
myScenes[i] = '5'
myScenes[i] = '5'
myScenes[i] = '6pt1'
myScenes[i] = '6pt1'
myScenes[i] = '7pt1'
myScenes[i] = '7pt10'
myScenes[i] = '7pt10'
myScenes[i] = '7pt12'
myScenes[i] = '7pt14'
myScenes[i] = '7pt4'
myScenes[i] = '7pt4'
myScenes[i] = '7pt5'
myScenes[i] = '7pt5'
myScenes[i] = '7pt5'
myScenes[i] = '7pt6'
myScenes[i] = '7pt6'
myScenes[i] = '7pt6'
myScenes[i] = '7pt7'
myScenes[i] = '7pt7'
myScenes[i] = '7pt8'
myScenes[i] = '7pt8'
myScenes[i] = '8pt1'
myScenes[i] = '8pt1'
myScenes[i] = '9'
myScenes[i] = '9'
myScenes[i] = '9'
myScenes[i] = '9'
Error : java.lang.ArrayIndexOutOfBoundsException: 1
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22944666
Well the erroring value could be 'off screen'. Can you post the values as a text file attachment?
0
 

Author Comment

by:OggieOne
ID: 22944706
Those were all the values, but here it is in a txt file.
SceneValues.txt
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 2000 total points
ID: 22945332
Oops - using the wrong array. Should be
            result = Integer.parseInt(buf1[0]) - Integer.parseInt(buf2[0]);
            if (result == 0) {
                result = Integer.parseInt(buf1[1]) - Integer.parseInt(buf2[1]);
            }

Open in new window

0
 

Author Comment

by:OggieOne
ID: 22945408
Sweet! It seems to work now from my actuall application! Thank you soooo much for your help I truly appreciate it.
0
 

Author Closing Comment

by:OggieOne
ID: 31515398
The help I got was fantastic. A stubborn problem was finally solved. Thanks so much.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22968243
:-)
0
 

Author Comment

by:OggieOne
ID: 22972569
Argh! OK, is there a way you can tweak the sort to allow this kind of a data value?
38/40pt3

THANKS!!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22974185
Your situation is not supportable, as i mentioned earlier, since there's potentially an infinite number of tweaks that will need to be performed. I could be open to discussions of micropayment however if you contact me through my profile details
0
 

Author Comment

by:OggieOne
ID: 22975630
I will try to contact you through your profile but will post this here anyway.

I should clarify. The following doesn't sort and throws a NumberFormatException
'37pt3'
'38/40pt3'
'38/40pt6'
'41'
'45/46pt5'
'48'
'50pt1'
'51'
'61pt4'
'66'
'67pt2'
'68pt7'
'69pt2'
'70'
'71'
'72pt1'
'79pt1'
'79pt3'
'79pt5'

If I add for example scene '1' to this list the sort then works. Is it some of initialization error? So the 38/40pt3 does actually sort. Pretty weird. Thoughts?
Thanks!

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month20 days, 5 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question