?
Solved

StringBuffer's into Array

Posted on 2000-03-12
6
Medium Priority
?
1,463 Views
Last Modified: 2008-02-26
I want to put 5 different Stringbuffer's into an Array that i can use the Index 0 to 4.
Can you help me?
0
Comment
Question by:MartinSchuster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:rjackman
ID: 2610039
instead of using array use vector


StringBuffer sb1 = new StringBuffer();
StringBuffer sb2 = new StringBuffer();
StringBuffer sb3 = new StringBuffer();
StringBuffer sb4 = new StringBuffer();

Vector v = new Vector();
StringBuffer StrBuff[];
sb1.append(some data);
sb2.append(some data);
sb3.append(some data);
sb4.append(some data);

v.addElement(sb1);
v.addElement(sb2);
v.addElement(sb3);
v.addElement(sb4);

so while retrieving u have to do

for(int i = 0 ;i<v.size();i++)
{
   
  StrBuf[i] =(StringBuffer) v.elementAt(i);
   
}

RJackman
0
 

Accepted Solution

by:
darrenc earned 800 total points
ID: 2610981
Hi Martin,

The easiest way to do this is to simply initialise a StringBuffer array and then populate it.

Here's an example

*** test.java ***
import java.util.*;

public class test {
   public static void main(String args[]) {
        StringBuffer buffArray[] = new StringBuffer[5];
        buffArray[0] = new StringBuffer();
        buffArray[1] = new StringBuffer();
        buffArray[0].append("Hello");
        buffArray[1].append("Hi");
        System.out.println(buffArray[0].toString());
        System.out.println(buffArray[1].toString());
   }
}

*** end test.java ***

Hope that helps
Darren
0
 
LVL 1

Expert Comment

by:techtime
ID: 2611032
And what is the problem with that?
Though rjackman is right here is the code that seem to work & be exactly what you've asked for:

StringBuffer sbA[] = new StringBuffer[5];

for(int i=0;i<5;i++)
 sbA[i] = new StringBuffer();

for(int i=0;i<5;i++)
 sbA[i].append("Here is sb#"+i);

for(int i=0;i<5;i++)
  System.out.println(sbA[i]);

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:darrenc
ID: 2614048
Hi,

Yes you are right ... the original code fragment from rjackman would work (sorry if anyone thought I meant that the original comment was wrong)

Darren
0
 
LVL 1

Expert Comment

by:techtime
ID: 2614794
Well dear darrenc my comment had nothing to do with yours in fact I've posted it before you... Alas, the network says its word.
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2751166
Martin, this looks like a duplicate of question http://www1.experts-exchange.com/Computers/Programming/Languages/Java/Q_10309649.html.

Did any of the comments on either question help you?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question