• Post Reply 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

How to add points of an arraylist into another arraylist?  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create an arraylist pointa that add point of another arraylist when swipe from left to right.However, it seems pointa cant add points into the array.Can you help me identify the problem?Thank you.

 
Marshal
Posts: 64166
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show us where you are adding the two Lists together. Why are you initialising the List in line 68? Why are you using floats? I don't think anybody should use floats for arithmetic.
 
capri blue
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pointlist arraylist is added at line 77. Pointa  arraylist at line 151. I am using float as my points require precision.
 
Campbell Ritchie
Marshal
Posts: 64166
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

capri blue wrote:Pointlist arraylist is added at line 77. Pointa  arraylist at line 151.

No, you are not adding points from one List to the other. You have two Independent operations there, and there is no way you can be confident that you have any correlation between the two Lists.
It may be a bad idea to have two Lists in the first place, but that is a different question.

I am using float as my points require precision.

. . . and precision is the one thing you don't get if you use floats. If you are going to use floating‑point arithmetic, use doubles. They aren't precise either, but the imprecision is much less.
 
capri blue
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can these code
 Point point3 = pointlist.get(z);
                  float x = point3.getX();
                  float y = point3.getY();
                    pointa.add(new Point(pointlist.get(z)));

shows the correlation between the two arraylist?
Can you tell me why is it bad to put two arraylist?
I am still a beginner here. I hope you don't mind explaining. Thanks a lot!
 
Sheriff
Posts: 24374
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

capri blue wrote:Can you tell me why is it bad to put two arraylist?



No, it's the other way around. Why do you need two lists?

The name "pointa" tells us nothing about what that list is for. As a beginner one of the first rules you need to learn is "Use meaningful variable names". So why not start there?
 
Paul Clapham
Sheriff
Posts: 24374
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's lines 150 and 151:



Why are you creating a new Point object to add to that other list? Why not just this:



Well, hopefully the Point class is immutable, in other words once you create a Point object it isn't possible to change its x and y values. Is that the case?
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!