Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

arraylist group by id.

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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};
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
trhis is no different to your other recent thread

https://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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I apologize but this problem I just can not solve, you can help I thank you in advance
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
new ArrayList[2];

OK, that's the declaration, where's the class instance?
class instance = new .....();//notice the ()
 
liulca ruggiero
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
> 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();
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Michael Dunn wrote:trhis is no different to your other recent thread

https://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.
    Bookmark Topic Watch Topic
  • New Topic