Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to I convert this Sentence String to StringBuffer?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to I convert this Sentence String to StringBuffer?

    import java.util.ArrayList;
    public class string
    {
    public static void main(String[] args)
    {
    String n1 = "That ";
    String n2 = "is ";
    String n3 = "a ";
    String n4 = "BOSS ";
    String n5 = "Zefron ";
    String n6 = "poster! ";
    ArrayList sentence = new ArrayList ();
    sentence.add (0, n1);
    sentence.add (1, n2);
    sentence.add (2, n3);
    sentence.add (3, n4);
    sentence.add (4, n5);
    sentence.add (5, n6);
    System.out.print(sentence.get(0));
    System.out.print(sentence.get(1));
    System.out.print(sentence.get(2));
    System.out.print(sentence.get(3));
    System.out.print(sentence.get(4));
    System.out.print(sentence.get(5));
    }
    }


  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: How to I convert this Sentence String to StringBuffer?

    Hello iCitationNeeded!
    A way to do that is to create a new StringBuffer object and then loop through your ArrayList (sentence) and append each element to the StringBuffer object you created. Check out the the StringBuffer javadoc. You can also use StringBuilder the same way.

  3. #3
    Junior Member
    Join Date
    May 2012
    Location
    Cluj
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to I convert this Sentence String to StringBuffer?

    A solution is this:

    ...edited by moderator
    Last edited by copeg; May 18th, 2012 at 11:35 PM.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,273
    Thanks
    177
    Thanked 822 Times in 765 Posts
    Blog Entries
    5

    Default Re: How to I convert this Sentence String to StringBuffer?

    kisssandor17, please read the forum rules and the following article.

    The Problem with Spoon-feeding

    Your post has been edited.

  5. #5
    Junior Member
    Join Date
    May 2012
    Location
    Cluj
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to I convert this Sentence String to StringBuffer?

    I learned something useful today...
    Sorry for my first post.

Similar Threads

  1. Method to take in a string sentence and reverse the tokens
    By ksahakian21 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 25th, 2012, 05:11 PM
  2. [SOLVED] convert int to String
    By itispj in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 14th, 2011, 10:34 PM
  3. Conversion of string into integer in Java
    By JavaPF in forum Java Programming Tutorials
    Replies: 17
    Last Post: January 23rd, 2010, 08:33 AM
  4. Convert string to int?
    By connex in forum Java Theory & Questions
    Replies: 1
    Last Post: December 9th, 2009, 04:06 AM
  5. String Vs StringBuffer
    By kalees in forum Java SE APIs
    Replies: 5
    Last Post: November 6th, 2009, 02:27 AM