views:

53

answers:

3

I have to write a function that prepends if boolean is true or append if boolean is false a string to an array. I'm not exactly sure what this means? Do I just add a string to the first element of the array if I'm prepending or add a string to the last element of the array if I'm appending? Or what?

+1  A: 

Well the question states that append string to array depending on Boolean. Convert string to array and add each character to the Array. Appending to easy and for pre-pending you need to write a array routine to move the array elements to provide space for pre-pending string characters.

A_Var
+2  A: 

That could either mean append the String to the last String of the array or add a new element in your array.

But I really think that's about adding elements in an array (either at the start or at the end of the array).

Colin Hebert
A: 

You could user StringBuilder instead of using array and just append ur string at the first of the stringBulder . E.g: StringBuilder str = new StringBuilder(); str.append("everyBody"); str.insert(0, "hello "); System.out.println(str.toString());

Alaa
As it's an assignment I don't think he can bend the rules ;)
Colin Hebert
ok , try to rewrite ur question in other clear words!
Alaa