About 143,000 results
Open links in new tab
  1. Sort a single String in Java - Stack Overflow

    sort string array in java. 0. Sorting a String using java collections. 1. Sorting a String in java. 0 ...

  2. How can I sort an ArrayList of Strings in Java? - Stack Overflow

    Oct 24, 2012 · Check Collections#sort method. This automatically sorts your list according to natural ordering. You can apply this method on each sublist you obtain using List#subList method. private List<String> teamsName = new ArrayList<String>(); List<String> subList = teamsName.subList(1, teamsName.size()); Collections.sort(subList);

  3. java - How are String sorted? - Stack Overflow

    Feb 19, 2014 · For String, the docs describes this as: Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string.

  4. java - Sorting characters alphabetically in a String - Stack Overflow

    String input = "hello"; char[] charArray = input.toCharArray(); Arrays.sort(charArray); String sortedString = new String(charArray); System.out.println(sortedString); Or if you want to sort the array using for loop (for learning purpose) you may use (But I think the first one is best option ) the following code snippet-

  5. How do I sort strings that contain numbers in Java

    Nov 17, 2016 · If the numbers are all single digit, split the string into a char array and sort the array. otherwise there has to be a delimiter to seperate the numbers. call string.split using that delimiter and sort the resulting array. The function to sort is Arrays.sort() if memory serves me right. javadoc references

  6. java - How to sort String array by length using Arrays.sort() - Stack ...

    Mar 8, 2016 · I am trying to sort an array of strings according to their length using Arrays.sort(), but this sorts the strings lexicographically rather than by length. Here is my code: S = "No one could disent...

  7. How can i sort a string without using sort () method in java?

    Mar 20, 2011 · // Java program to sort // a string of characters public class SortString{ static final int MAX_CHAR = 26; // function to print string in sorted order static void sortString(String str) { // Hash array to keep count of characters.

  8. java - Sorting an array of String with custom ordering - Stack …

    May 14, 2013 · Java how to sort string array based on order values were placed? 0. Java sorting array with strings. 0. ...

  9. Sorting Strings that contains number in Java - Stack Overflow

    I have problem with default comparator for Strings (in SortedSet). The problem is that default comparator doesn't sort good String that contains numbers i.e.: In set i have: room1, room2, room100

  10. java - Comparing two string and sorting them in alphabetical …

    Dec 7, 2013 · I want to compare two strings and sort them in alphabetical order. I am currently creating two arrays with the strings and sorting one them comparing the two arrays. String a="LetterA"; String b="

Refresh