uppercase - Java converting upper to lower sorting -
i have program sorts lines in text file , puts them in alphabetical order can't sort first word because first word's first letter uppercase , word has have first letter upper case , have no idea how it.
this text file:
santa, better watch step!
how doggie in window?
the quick brown fox jumped on lazy dog.
have read khuth's programming series?
it doesn't better this!
here code:
import java.io.*; import java.util.*; public class wordsorter { public static void main(string[] args) throws exception { string firsttextfile = "prob10.in.txt"; string secondtextfile = "prob10.out.txt"; scanner document = null; printwriter newfile = null; string inputfile = ""; string outputfile = ""; try{ document = new scanner(new file(firsttextfile)); } catch(exception e){ system.out.println("could not find " + firsttextfile); system.exit(0); } try{ newfile = new printwriter(new fileoutputstream(secondtextfile, true)); } catch(exception f){ system.out.println("could not find " + secondtextfile); system.exit(0); } while (document.hasnextline()){ inputfile = document.nextline(); string line = inputfile; line = line.tolowercase(); string[] words = line.split(" "); arrays.sort(words); newfile.println(arrays.tostring(words)); } document.close(); newfile.close(); }
}
take @ java's collator ... , since new java have @ example on java coderanch
Comments
Post a Comment