Results 1 to 4 of 4
Thread: ArrayList + String/StringBuffer
- 04-17-2012, 03:28 PM #1
Senior Member
- Join Date
- Jan 2012
- Posts
- 146
- Rep Power
- 0
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...
Can I put x.append() inside the al.add() method? So it would look like: al.add(x.append("Hello")); ?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() } }
- 04-17-2012, 03:58 PM #2
Re: ArrayList + String/StringBuffer
What happened when you coded it and compiled it?Can I put x.append() inside the al.add() method
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.
- 04-17-2012, 08:19 PM #3
Senior Member
- Join Date
- Apr 2012
- Posts
- 199
- Rep Power
- 0
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.
- 04-17-2012, 08:28 PM #4
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
-
String vs. StringBuilder vs. StringBuffer
By stchman in forum New To JavaReplies: 5Last Post: 01-12-2012, 07:52 AM -
Test for all empty Strings in LinkedHashMap<String,ArrayList<String>
By albertkao in forum New To JavaReplies: 1Last Post: 11-04-2010, 06:53 PM -
Easiest way to convert String to StringBuffer
By unideal in forum New To JavaReplies: 4Last Post: 12-13-2009, 12:43 PM -
java.lang.StringBuffer.append(StringBuffer.java(Co mpiled Code))
By Ashok Dave in forum Advanced JavaReplies: 3Last Post: 03-04-2009, 06:03 AM -
java.lang.StringBuffer.append(StringBuffer.java(Co mpiled Code))
By Ashok Dave in forum New To JavaReplies: 1Last Post: 03-03-2009, 05:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks