Results 1 to 6 of 6

Thread: Sort String

  1. #1
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default Sort String

    why the output of this program is character:

    import java.util.*;

    public class array {


    public static void main(String[] args) {

    String[] strArray = new String[] {"z", "a", "C"};
    Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER);
    System.out.println(strArray);
    }
    }

    output is:[Ljava.lang.String;@1a46e30:confused:
    :cool:

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You're getting the toString() representation of an array. to display an array, either loop through it with System.out.println calls within the loop, or use
    Java Code:
    System.out.println(java.util.Arrays.toString(strArray));

  3. #3
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    ok sir. got it. thank you so much.
    but is it natural that the output will have this symbols [string here]?

    example. output: [kier,kyle] instead of kier,kyle.
    :cool:

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    How about using a loop to iterate through the array while printing.

  5. #5
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    hi, can you help how? @dswastik:)
    :cool:

  6. #6
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Java Code:
    for(int x=0;x<strArray.length;x++){
       System.out.println(strArray[x]);
    }

Similar Threads

  1. Using Merge Sort to sort an ArrayList of Strings
    By coldfire in forum New To Java
    Replies: 3
    Last Post: 03-13-2009, 01:03 AM
  2. Replies: 3
    Last Post: 01-26-2009, 12:20 AM
  3. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM
  4. sort
    By Camden in forum New To Java
    Replies: 7
    Last Post: 11-28-2007, 01:11 AM
  5. how to sort
    By Feng in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 06:56 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
  •