Results 1 to 4 of 4
  1. #1
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default ArrayList + String/StringBuffer

    Write two programs: one using the String class and one using the StringBuffer class. Your programs should store a set of Strings in an ArrayList and print those Strings in the order by which they are added. The output of your programs should create a complete sentence.

    I'm kind of confused... this is what I'm starting out with...

    Java Code:
    package OOP;
    import java.util.*;
    
    public class StringUnit {
    	public static void main (String [] args){
    		ArrayList aL = new ArrayList();
    		String x = new String();
    		
    		al.add()
    	}
    
    }
    Can I put x.append() inside the al.add() method? So it would look like: al.add(x.append("Hello")); ?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: ArrayList + String/StringBuffer

    Can I put x.append() inside the al.add() method
    What happened when you coded it and compiled it?

    You can if the append() method returns a value that can be added.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: ArrayList + String/StringBuffer

    Using a good IDE will help significantly. For example, the Netbeans IDE has code completion. After typing the . symbol after the object, the IDE will list the objects methods as shown below.

    From the list of methods, you can find out if there's a method that will take the type of parameters that you want.

    You can then select one of the methods from the list by scrolling up and down.

    ArrayList + String/StringBuffer-ide_codecompletion.png

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: ArrayList + String/StringBuffer

    The problem with using IDEs for beginners is that they never learn how things work. As soon as they need to do something away from the IDE they are lost. Also the IDEs don't seem to use the javac command's -Xlint option and the user misses seeing an important warning message. I see it many times a week.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. String vs. StringBuilder vs. StringBuffer
    By stchman in forum New To Java
    Replies: 5
    Last Post: 01-12-2012, 07:52 AM
  2. Replies: 1
    Last Post: 11-04-2010, 06:53 PM
  3. Easiest way to convert String to StringBuffer
    By unideal in forum New To Java
    Replies: 4
    Last Post: 12-13-2009, 12:43 PM
  4. Replies: 3
    Last Post: 03-04-2009, 06:03 AM
  5. Replies: 1
    Last Post: 03-03-2009, 05:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •