Sorting String

Sorting String

Looking for an example to sort string in Java.

View Answers

April 4, 2008 at 6:04 PM

Hi

ShortString.java

import java.util.*;
import java.io.*;

public class ShortString{
String [] words = { "sontosh","Amardeep", "vinod", "Deepak", "Suman" };

public static void main(String args[]) {
new ShortString().doit();
}
public void doit(){
try {
Writer writer = new BufferedWriter(new OutputStreamWriter(System.out, "Cp850"));
writer.write("Before shorting :\n");
for(int i=0; i < 5 ; i++) {
writer.write(words[i] + " ");
}
java.util.Arrays.sort(words);
writer.write("\nAfter shorting :\n");
for(int i=0; i < 5 ; i++) {
writer.write(words[i] + " ");
}
writer.write("\n");
writer.flush();
writer.close();
}
catch(Exception e){
System.out.println(e);
}
}
}


---------------------------------

run the given above code. I hope, you are satisfy this program.

amar









Related Tutorials/Questions & Answers:
Sorting the letters in a String
Sorting the letters in a String  I have recently learned how to sort different strings using the insertion sort method but I still cannot sort the letters in one particular string. For instance, if I enter in the string "Hello my
sorting an array of string with duplicate values - Java Beginners
sorting an array of string  Example to sort array string
Advertisements
sorting an array of string with duplicate values - Java Beginners
sorting an array of string with duplicate values  I have a sort method which sorts an array of strings. But if there are duplicates in the array it would not sort properly
Sorting String arrays in java - Java Beginners
Sorting String arrays in java  I have to make an interface... not think that my sorting thusfar is correct. Can anyone help? Please help... InterfaceStringArray { private String[] arr; //ref to array arr private int
sorting an array of string with duplicate values - Java Beginners
string with duplicate values  How to check the string with duplicate values
sorting an array of string with duplicate values - Java Beginners
String of Array  What is mean by string of array? And how one can add, delete the records from database in string format
sorting
sorting   write a program to arrange sorting in rows,column and diagonal
Sorting
Sorting  can any help me know which sorting algorithm java uses for sorting collection and arrays
sorting
sorting  write to a program to arrange the sorting in rows, column and digonal
sorting
sorting  how to do sorting without using bubble sort,selection sort
sorting
sorting  write a program which sort by lastname if the string of list is "firstnamelastname" i)66aa,cckk,ddac
sorting
repeated character in a string. //sample string "abccdeafbdh" } 3)print("code
Sorting in Java
Sorting in Java  Sorting in Java
Sorting Program
Sorting Program  To sort 10items in alphabetical order   ...{ public static void main(String[] args) { String array[]=new String[5]; Scanner input = new Scanner(System.in); System.out.println
linear sorting
linear sorting  what is linear sorting? can any send me an example...("After Sorting: "); for(int i=0;i<arr.length;i++){ System.out.println(arr[i]); } } public static void main(String[] args
group by sorting
group by sorting  group by sorting of data in SQL
sorting numbers
sorting numbers  How to sort the numbers in ascending order   import java.util.*; class SortNumbers{ public static void main(String[] args) { Scanner input=new Scanner(System.in
Sorting an ArrayList
Sorting an ArrayList  print("code sample");Hello All, I am working on a program for school and I am having trouble with sorting my list...; /** * */ public class GTT1_Task2B{ public static void main(String[] args) throws
Sorting and Searching
Sorting and Searching  Hi i would really be thankful if someone could help me with this A program is required to ask users to rate the Java... java.util.*; class RateJava { public static void main(String[] args
merge sorting in arrays - Java Beginners
merge sorting in arrays  Write a program to insert string or characters to an array and apply merge sorting on this array  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners
sorting array in java
sorting array in java  How to sort array in Java or JavaScript?   JavaScript Sorting array tutorial   Java Sort array of strings import java.util.*; class ArrayExample{ public static void main(String
Sorting the array
Sorting the array  Implement a program to process votes for 5 candidates in a talent contest. The program should use a String array to hold the names... VoteCount { public static void main(String[] args) { //create empty array
sorting and storing data
sorting and storing data   sorting and storing data in UITableView
String sort() Method
String sort() Method       In this program you will learn how to sort words in a String. The sorting will be done in ascending order. We are going to use sort() method
Java sorting
sorting mechanism. say about Collections.Sort() & Arrays.Sort() that uses
sorting
STRING.....
STRING.....  plzz sent me d code for counting vowels in a string... gui programme
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both... "String args[]" can mean a "string array called args which is an array
string
string  String helloString = new String(helloArray); System.out.println(helloString); i am unable to understand this. could u plz explain
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
String
String  how to add spaces with string functions.?   Hi... { public static String addSpaceToRight(String s, int n) { return String.format("%1$-" + n + "s", s); } public static String addSpaceToLeft(String s, int n
Bubble Sorting in Java
Bubble Sorting in Java  Hi, What is Bubble Sorting? Guide me where to learn Bubble Sorting in Java? Thanks   Hi, Check the tutorial at Bubble Sorting in Java. Thanks
String
characters in string?   import java.util.*; class RemoveDuplicateCharatcersFromString { public static String removeDuplicates(String s... < s.length(); i++) { String st = s.substring(i, i + 1
Java Sorting
should use a String array to hold the names of the 5 candidates and an integer... java.io.*; import java.util.*; class Candidate{ public String name; public int vote ; public Candidate(){} public Candidate(String name,int vote) { super
String
String  write down the code of remove any character from a given string without using any string function   please give me the code of remove any given character from a given string without using function
string
string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
string
*; class ExtractWords { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String: "); String st=input.nextLine(); String str[]=st.split
string
string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C...; public class StringTest { public static void main(String [] args
string
string  write a program to accept the string and store the reverse stream into another array and print
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  java prgm to find total occurence of a given string pattern in a sentence
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
String
String  how to print in between numbers if the question "String s = "1,2,3,4,5,6,8,-25"" out must be 1 2,3,4,5,6,7,8,9,10,upto25
string
and also displaying that contain word? Like I want to find "a" in the string... and a character. It then count the occurrence of that character in the string and display... String_Example { public static void main(String[] args
number sorting
SortListInDescendingOrder{ public static void main(String[] args) { Scanner
string
string  program for String reverse and replace in c,c++,java e.g.Input:10,20,hello output:hello;20;10   Hi Friend, Try the following java...(String[] args) { String array[]=new String[5]; Scanner input
SORTING - Java Interview Questions
{ public static void main(String args[]) { ArrayList list= new ArrayList...("Items after sorting are ="+list); } } Thanks
Java Sorting and Searching
Java Sorting and Searching   If anyone could help me with this I would be really thankful! Write a program that stores the names of these artists in a String array. The program should prompt the user to enter the name
ModuleNotFoundError: No module named 'sorting'
ModuleNotFoundError: No module named 'sorting'  Hi, My Python... 'sorting' How to remove the ModuleNotFoundError: No module named 'sorting... to install padas library. You can install sorting python with following command

Ads