File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes arraylist group by id. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

arraylist group by id.

liulca ruggiero
Greenhorn

Joined: Nov 21, 2012
Posts: 15
how to group the data in numeric format in an array I thank you in advance


Set<coordinates> group = new LinkedHashSet<coordinates>();


//group id = 1 . id x y
group.add(new coordinates(1, 50, 20));
group.add(new coordinates(1, 70, 30));
group.add(new coordinates(1, 50, 40));


//group id = 2
group.add(new coordinates(2, 100, 20));
group.add(new coordinates(2, 130, 30));
group.add(new coordinates(2, 140, 40));
group.add(new coordinates(2, 140, 40));


//the result should be the following

group id = 1 x={50,70,50}; y={20,30.40};

group id = 2 x={100,130,140,140}; y={20,30,40,40};
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
trhis is no different to your other recent thread

http://www.coderanch.com/t/598886/GUI/java/drawing-polygons

and you were told there how to do it.

are you just waiting for someone to post the code for you?
liulca ruggiero
Greenhorn

Joined: Nov 21, 2012
Posts: 15
I apologize but this problem I just can not solve, you can help I thank you in advance
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I've already given you the steps, and a rough pseudo code for the separation.

I can only help further if you post your attempt at following those steps
liulca ruggiero
Greenhorn

Joined: Nov 21, 2012
Posts: 15
I am doing as you tell me error thank you for your patience.

ArrayList[] j = new ArrayList[2];

for (coordinates n : group) {
j[n.getID()-1].add(n);
System.out.println(j);
}

error
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
new ArrayList[2];

OK, that's the declaration, where's the class instance?
class instance = new .....();//notice the ()
liulca ruggiero
Greenhorn

Joined: Nov 21, 2012
Posts: 15
I'm sorry but I do not understand what you mean by class instance = new ..... () ;/ / notice the ()
you can give a few examples I thank you in advance asking for your help
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> you can give a few examples I thank you in advance asking for your help

not nasty here, but have you ever written a java program?

if so, what do you think these are

= new JButton[];
= new JButton();
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Michael Dunn wrote:trhis is no different to your other recent thread

http://www.coderanch.com/t/598886/GUI/java/drawing-polygons

and you were told there how to do it. . . .
Please read this. I am closing this discussion to avoid duplication of effort.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: arraylist group by id.