0

I have a arraylist containing values like [ addidas 5 100 , nike 10 300 , woodland 4 800] so if i print am gettinh result as

value1 :: adidas
value2 :: 5
value3 :: 100

result has to be like

value1 :: adidas,nike,woodland
value2 :: 5,10,4
value3 :: 100,300,800
ArrayList<String> array;

int j = 0;

String[] parts;
String value1;
String value2;
String value3;

for (j = 0; j <= array.size(); j++) {

    parts = array.split(" ");

    value1 = parts[0];
    value2 = parts[1];
    value3 = parts[2];

    System.out.println("value1::" + value1);
    System.out.println("value2::" + value2);
    System.out.println("value3::" + value3);

}
9
  • parse the array into Value objects. Commented Oct 12, 2013 at 22:56
  • parts = array.split(" "); what are you trying to achieve here? Commented Oct 12, 2013 at 22:57
  • I think he/she means array.get(j).split(" "); Commented Oct 12, 2013 at 22:58
  • Where is the code where you're actually putting stuff into the array? Commented Oct 12, 2013 at 22:59
  • 1
    I know @DavidWallace that is what I wanted to get from him/her Commented Oct 12, 2013 at 22:59

1 Answer 1

4

Since this looks like homework there will be no code here.
There is one error in your code and few in logic.

  • split can be invoked on String so first you should get that string from your array list
  • you said that you want to print all elements of the same category (value1, value2, value3) in same line but your loop prints one value of each category in each iteration. To solve this problem you should store split values in separated lists and print them after loop ends.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.