Results 1 to 7 of 7
- 03-21-2011, 10:03 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 85
- Rep Power
- 0
Code review on adding sentences to String array
What is the best way to form an array of sentences.
The below code breaks the paragraph into sentences. I want to add each of the sentence into a String array.
I am currently adding it to a list and then converting it back to array.Java Code:public class TestExample { public static final String EXAMPLE_TEST = "Wave supports Robots and Gadgets. A robot runs on the server while the gadget runs on the client. The gadget will manipulate the Wave XML locally and the delta is send to the server"; public static void main(String[] args) { List<String> list = new ArrayList<String>(); BreakIterator bi = BreakIterator.getSentenceInstance(); bi.setText(EXAMPLE_TEST); int index = 0; while (bi.next() != BreakIterator.DONE) { String sentence = EXAMPLE_TEST.substring(index, bi.current()); index = bi.current(); list.add(sentence); System.out.println("Sentence: " + sentence); } String [] SentArr =list.toArray(new String[list.size()]); System.out.println("SentArr: " + SentArr); } }
- 03-21-2011, 10:46 AM #2
You just can use String#split and RegExp and to have the same result.
Skype: petrarsentev
http://TrackStudio.com
- 03-21-2011, 10:50 AM #3
Member
- Join Date
- Sep 2008
- Posts
- 85
- Rep Power
- 0
The problem of using String split is it would even split out acronyms. I need to keep acronyms together.
- 03-21-2011, 11:12 AM #4
I thing your code is fair, just small chane
String sentence...........instead of this create StringBuilder object and create it outside loopsanjeev,संजीव
- 03-21-2011, 11:57 AM #5
So What is this "BreakIterator" in your code? Do you use some special library or it's your code too?
Skype: petrarsentev
http://TrackStudio.com
- 03-21-2011, 01:54 PM #6
Um, java.text.BreakIterator
BreakIterator (Java Platform SE 6)
db
- 03-21-2011, 02:27 PM #7
Member
- Join Date
- Sep 2008
- Posts
- 85
- Rep Power
- 0
Similar Threads
-
Receiving code review
By sunde887 in forum New To JavaReplies: 0Last Post: 03-08-2011, 05:31 AM -
Memory Leak questions, code review
By mensaFool in forum Advanced JavaReplies: 9Last Post: 03-08-2010, 04:27 PM -
adding in array String
By Mekonom in forum New To JavaReplies: 4Last Post: 12-10-2009, 04:28 PM -
please review the following code
By ajbj in forum New To JavaReplies: 3Last Post: 08-25-2009, 08:37 AM -
[SOLVED] Code review
By saeedsubedar in forum Advanced JavaReplies: 14Last Post: 06-25-2008, 05:25 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks