Results 1 to 5 of 5

Thread: String []Array

  1. #1
    Warren is offline Member
    Join Date
    Nov 2007
    Posts
    8
    Rep Power
    0

    Default String []Array

    how can Bubble Sort be implemented on String Array?

  2. #2
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

  3. #3
    Warren is offline Member
    Join Date
    Nov 2007
    Posts
    8
    Rep Power
    0

    Default

    thats for integers. anyway thanx.

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    String implements the Comparable interface so you can use
    str1.compareTo(str2) and use the return value for ordering.

  5. #5
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    They are for integers, but they still show how the basic of a Bubble Sort works.
    Java Code:
    	public static void bubleSort(String[] ar) {
    		int n = ar.length;
    
    		for (int pass = 1; pass < n; pass++) {
    			for (int i = 0; i < n - pass; i++) {
    				if (ar[i].compareTo(ar[i + 1]) > 0) {
    					String tmp = ar[i];
    					ar[i] = ar[i + 1];
    					ar[i + 1] = tmp;
    				}
    			}
    		}
    	}

Similar Threads

  1. Convert a vector to a string array
    By orchid in forum New To Java
    Replies: 4
    Last Post: 02-24-2010, 02:31 AM
  2. How i add string array in vector
    By susan in forum New To Java
    Replies: 7
    Last Post: 02-12-2009, 01:32 PM
  3. JSP to output Java String Array
    By irenavassilia in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-31-2008, 04:11 PM
  4. Help with string and array in java
    By zoe in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:12 AM
  5. Replies: 1
    Last Post: 08-03-2007, 10:52 AM

Posting Permissions

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