I have an arraylist of arraylists which stores distances between points. I need to keep the original indexes of the distances after sorting the arraylist, because I need to find the K-nearest neighbours at a later stage of the code. The class I have implemented does not output the correct index of the distances instead an index of the arraylists only is the output
I have tried implementing a 2D comparable class but I was given a few errors.
public staticArrayList<ArrayList<Double>>distance(ArrayList<sample_points> points) {
ArrayList<ArrayList<Double>> distArray = new ArrayList<ArrayList<Double>>(points.size());
double dist = 0;
List<Element> elements = new ArrayList<Element>();
for(int i = 0; i<points.size()-1; i++) {
ArrayList<Double> distances = new ArrayList<Double>();
for(int j=i+1; j<points.size(); j++){
// do your calculations here
dist = Math.sqrt(Math.pow(points.get(i).getX() - points.get(j).getX(), 2)
+ Math.pow(points.get(i).getY() - points.get(j).getY(), 2));
distances.add(dist);// add the distance to the current distances list
}
distArray.add(distances);//
}
System.out.print("Distances: "distArray);
System.out.println();
for(int i = 0; i < distArray.size(); i++) {
for (int j = 0; j < distArray.get(i).size(); j++) {
elements.add(new Element(i, distArray.get(i).get(j)));
}
}
Collections.sort(elements);
for(int i = 0; i < elements.size(); i++) {
System.out.println("Dist "+ elements.get(i).distance + " "
+ "Index " + elements.get(i).index+" ");
}
}
Here is my comparable class:
class Element implements Comparable<Element>{
public final int index;
public final double distance;
public Element(int index, double distance){
this.index = index;
this.distance = distance;
}
#Override
public int compareTo(Element e){
return Double.valueOf(this.distance).compareTo(Double.valueOf(e.distance));
}
}
Expected results:
Distances: [[2.8284271247461903, 5.830951894845301, 7.280109889280518],
[3.1622776601683795, 5.0], [2.23606797749979]]
Dist 2.23606797749979 Index 0
Dist 2.8284271247461903 Index 0
Dist 3.1622776601683795 Index 0
Dist 5.0 Index 1
Dist 5.830951894845301 Index 1
Dist 7.280109889280518 Index 2
Actual results:
Distances: [[2.8284271247461903, 5.830951894845301, 7.280109889280518],
[3.1622776601683795, 5.0], [2.23606797749979]]
Dist 2.23606797749979 Index 2
Dist 2.8284271247461903 Index 0
Dist 3.1622776601683795 Index 1
Dist 5.0 Index 1
Dist 5.830951894845301 Index 0
Dist 7.280109889280518 Index 0
On review of your code, I think that the error is in your assumptions and that the output itself is in fact correct. The index that you're seeing is in fact the index of the outer Lists within your list of list nested array lists that you create here:
for (int i=0; i<points.size()-1; i++) {
ArrayList<Double> distances = new ArrayList<Double>();
for (int j=i+1; j < points.size(); j++) {
// do your calculations here
dist = Math.sqrt(Math.pow(points.get(i).getX() - points.get(j).getX(), 2)
+ Math.pow(points.get(i).getY() - points.get(j).getY(), 2));
distances.add(dist); // add the distance to the current distances list
}
distArray.add(distances); // ***** the index of items added here *****
}
If you add these debugging lines:
for (int i=0; i < points.size()-1; i++) {
ArrayList<Double> distances = new ArrayList<Double>();
for (int j=i+1; j<points.size(); j++) {
// do your calculations here
dist = Math.sqrt(Math.pow(points.get(i).getX() - points.get(j).getX(), 2)
+ Math.pow(points.get(i).getY() - points.get(j).getY(), 2));
distances.add(dist);// add the distance to the current distances list
}
distArray.add(distances); // ***** the index of items added here *****
// ******* add this ********
System.out.println(distArray.indexOf(distances));
System.out.println(distances);
System.out.println();
}
You'll see that this is correct. You need to either change how you create your index values or change your assumptions.
Also, your Element index fields are immutable and are being created before any items in the distance ArrayList are sorted, and so this field cannot represent the sort order of distances.
You state in comment:
If I have a 2D Arraylist of distances i.e [ [d1,d2,d3], [d4,d5], [d6] ]. The indices will be as follows d1=0, d2 =1, d3 = 2, d4 =0, d5 =1 and d6 =0. So I need to get the original indices as mentioned after I sort each arraylist.
Then use j to create the index, not i
for(int i = 0; i < distArray.size(); i++) {
for (int j = 0; j < distArray.get(i).size(); j++) {
// elements.add(new Element(i, distArray.get(i).get(j)));
elements.add(new Element(j, distArray.get(i).get(j))); // ***** note change *****
}
}
Side note: in the future, create a minimal runnable program that demonstrates the problem, that we can compile and run easily. For this question I had to create one myself:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Foo01 {
public static void main(String[] args) {
List<SamplePoints> points = new ArrayList<>();
int maxXY = 100;
int max = 4;
for (int i = 0; i < max; i++) {
int x = (int) (maxXY * Math.random());
int y = (int) (maxXY * Math.random());
points.add(new SamplePoints(x, y));
}
distance(points);
}
private static class SamplePoints {
private int x;
private int y;
public SamplePoints(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
private static class Element implements Comparable<Element> {
public final int index;
public final double distance;
public Element(int index, double distance) {
this.index = index;
this.distance = distance;
}
#Override
public int compareTo(Element e) {
return Double.valueOf(this.distance).compareTo(Double.valueOf(e.distance));
}
}
public static void distance(List<SamplePoints> points) {
ArrayList<ArrayList<Double>> distArray = new ArrayList<ArrayList<Double>>(points.size());
double dist = 0;
List<Element> elements = new ArrayList<Element>();
for (int i = 0; i < points.size() - 1; i++) {
ArrayList<Double> distances = new ArrayList<Double>();
for (int j = i + 1; j < points.size(); j++) {
// do your calculations here
dist = Math.sqrt(Math.pow(points.get(i).getX() - points.get(j).getX(), 2)
+ Math.pow(points.get(i).getY() - points.get(j).getY(), 2));
distances.add(dist);// add the distance to the current distances
// list
}
distArray.add(distances);//
System.out.println(distArray.indexOf(distances));
System.out.println(distances);
System.out.println();
}
System.out.print("Distances: " + distArray);
System.out.println();
for (int i = 0; i < distArray.size(); i++) {
for (int j = 0; j < distArray.get(i).size(); j++) {
elements.add(new Element(i, distArray.get(i).get(j)));
}
}
Collections.sort(elements);
for (int i = 0; i < elements.size(); i++) {
System.out.println("Dist " + elements.get(i).distance + " " + "Index "
+ elements.get(i).index + " ");
}
}
}
But in the future, you'll want to do this to help make your question easier to answer.
Related
Java Array List is overriding the data added and put the last items added only.
The output expected is 1.0, 1.0, -1.0,-1.0, -1.0, 1.0,-1.0, -1.0, -1.0,-1.0, -1.0, -1.0
But, the output I get is -1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0 .
The code override the list by last array elements which is a=[-1,-1,-1,-1]. That is why all 12 elements of the list value is overridden to -1.
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args){
double sum=0; int n=0,y=0,count=0,x=1;
double []a=new double []{1,0,1};
double []b=new double [a.length];
List<double[] >mylist= new ArrayList<>();
double [][]c=new double[][]{{0,0.66,0.66},{0.66,0,0.66},{0,0.66,0}};
mylist.add(0,a);
while(n>=0 && n<4){
for (int i = 0 ; i < 3 ; i++)
for (int j = 0 ; j < a.length; j++)
{
sum=sum+(c[i][j]*a[j]);
if(j==a.length-1)
{
if(sum>0)
sum=1;
else
sum=-1;
b[y]=sum;
y++;
count++;
sum=0;
}
if(count==a.length){
mylist.add(x,b);
x++;
y=0;
count=0;
for(int k=0;k<a.length;k++){
a[k]=b[k];
}
}
}n++;
}
for (int i = 0 ; i < mylist.size(); i++)
for (int j = 0 ; j < a.length ; j++)
{
System.out.print(mylist.get(i)[j]+",");
}
}
}
Arrays in Java are passed by reference to methods, you can check this link for detailed explanation "pass by referece and pass by value" for more about Java parameter passing.
In you code, you just have multiple references of array a and array b. So that is why when their values change all initial values also change. you can use a debugger and you will see it starts changing from the second insertion of b to the ArrayList.
To fix this create a copy of array a at the beginning (whose content will not change). for each new insertion, create a temporary array to hold the values and insert them to your ArrayList.
Below is a fix
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
double sum = 0;
int n = 0, y = 0, count = 0, x = 1;
double[] a = { 1, 0, 1 };
// Create a copy of a to insert at the beginning
double[] acpy = new double[] { 1, 0, 1 };
double[] b = new double[a.length];
List<double[]> mylist = new ArrayList<>();
double[][] c = new double[][] { { 0, 0.66, 0.66 }, { 0.66, 0, 0.66 }, { 0, 0.66, 0 } };
mylist.add(0, acpy);
double[] temp ;
while (n >= 0 && n < 4) {
// this will create a new reference whenever you are about to insert a new element
temp = new double[a.length];
for (int i = 0; i < 3; i++)
for (int j = 0; j < a.length; j++) {
sum = sum + (c[i][j] * a[j]);
if (j == a.length - 1) {
if (sum > 0)
sum = 1;
else
sum = -1;
b[y] = sum;
// copy values of b for insertion to ArrayList
temp[y] = sum;
y++;
count++;
sum = 0;
}
if (count == a.length) {
mylist.add(x, temp);
x++;
y = 0;
count = 0;
for (int k = 0; k < a.length; k++) {
a[k] = b[k];
}
}
}
n++;
}
for (int i = 0; i < mylist.size(); i++)
for (int j = 0; j < a.length; j++) {
System.out.print(mylist.get(i)[j] + ",");
}
}
}
I know this may stand for a silly question but I have got a lot of problems with this.
I will first explain how it should work :
1)Generate random Array with size in range <4,7>
2)Fill it with random elements in range <100, 999>
3)Print the index of three numbers with biggest digit sum
So the question is-how? I know I should implement this:
SumOfDigits += ElementFromArray % 10;
ElementFromArray /= 10;
But i have got no idea where. I tried to add this as a if (i>0) loop inside for loop-but its not working.
Also how at the end im going to print the proper elements? Should I use Arrays.sort(tab) and then System.out.println(tab[tab.length - 1]) (and so on with -2, -3 for 3 last elements)?
import java.util.Arrays;
import java.util.Random;
public class Ex1 {
public static void main(String[] args) {
Random rand = new Random();
int size = rand.nextInt(4) + 4;
int tab[] = new int[size];
for (int i = 0; i < tab.length; i++) {
int elements = rand.nextInt(900) + 100;
tab[i] = elements;
}
System.out.println(Arrays.toString(tab));
}
}
If we aim for a solution using only arrays I would use a 2d array to hold the sum of digits and the index of the corresponding number in the tab array
So first create the array based on the size of the original array
int[][] sums = new int[size][2];
then in the for loop, calculate the sum of the random number and store it and the index
sums[i][0] = elements / 100 + (elements / 10) % 10 + elements % 10;
sums[i][1] = i;
Then sort the sums array using a custom comparator
Arrays.sort(sums, new Comparator<int[]>() {
#Override
public int compare(int[] o1, int[] o2) {
return Integer.compare(o2[0], o1[0]);
}
});
And finally print the index and number of the numbers of the top 3
for (int i = 0; i < 3; i++) {
System.out.printf("%d: %d\n", sums[i][1], tab[sums[i][1]]);
}
Just use while loop: here is a quick and dirty solution:
private static void main10(String[] args) {
Random rand = new Random();
int size = rand.nextInt(4) + 4;
int[] tab = new int[size];
for (int i = 0; i < tab.length; i++) {
int element = rand.nextInt(900) + 100;
tab[i] = element;
}
System.out.println(Arrays.toString(tab));
// calculate digits:
int[] digitsums = new int[size];
for (int i = 0; i < tab.length; i++) {
int element = tab[i];
int sumOfDigits = 0;
while (element > 0) {
sumOfDigits += element % 10;
element /= 10;
}
digitsums[i] = sumOfDigits;
}
System.out.println(Arrays.toString(digitsums));
int[] copyOfdigitsums = Arrays.copyOf(digitsums, digitsums.length);
for (int i = 1; i <= 3; i++) {
int j = getIndexOfLargest(copyOfdigitsums);
System.out.println("index of " + i + "largest is " + j + ", with a digitsum of " + copyOfdigitsums[j]);
copyOfdigitsums[j] = 0;
}
}
static int getIndexOfLargest(int[] digitsums) {
int largest = 0;
int index = 0;
for (int i = 0; i < digitsums.length; i++) {
int d = digitsums[i];
if (largest < d) {
largest = d;
index = i;
}
}
return index;
}
I've input the points and found distances between them. Now I want to find which distance of m points is shortest.
import java.awt.Point;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
public class Solution
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
Point[] coordinates=new Point[10];
double dist;
for(int i = 0; i < m; i++)
{
coordinates[i]=new Point(in.nextInt(),in.nextInt());
}
for(int i=0;i<m-1;i++)
{
dist=Math.sqrt(((coordinates[i+1].getX()-coordinates[i].getX())*(coordinates[i+1].getX()-coordinates[i].getX()))+((coordinates[i+1].getY()-coordinates[i].getY())*(coordinates[1].getY()-coordinates[0].getY())));
System.out.println("dist between "+coordinates[i+1].getX()+","+coordinates[i+1].getY()+"and "+coordinates[i].getX()+","+coordinates[i].getY() +" is "+dist);
}
in.close();
}
}
The way your for loop is designed, it is only checking one point with the point that was read just after it. You need 2 for loops to compare each of the points with all the others
for(int i = 0; i < m - 1; i++)
{
for (int j = 0; j < m; j++)
{
// compare point i with point j and store the smallest here
// you probably want to discard points where i == j
}
}
You have to make a for-loop inside another one to go through all points per point. The first for-loop will go through every point. The second loop will also go through all points, so inside the second loop, you will have any possible combination of two loops. Then you need to calculate the distance and check if the distance calculated is smaller than the smallest distance calculated before.
In the end you'll have the smallest distance:
0.0f for points[] being size 0 or 1
smallest distance for points[] being size 2 or greater
Here's some example code:
float smallesDistance = 0.0f;
Point[] points = ...;
for(int i = 0; i < points.length; i++) {
for (int j = 0; j < points.length; j++) {
if(i != j) { //cant compare on point with itself
Point a = points[i];
Point b = points[j];
float distance = ...; //calculate distance with pythagorean theorem
if(distance < smallesDistance)
smallesDistance = distance;
}
}
}
If you need the greatest distance, just replace if(distance < smallesDistance) by if(distance > smallesDistance).
Here are the helper functions:
distance: calculate the distance between two points
shortest_pair: return the pair with the shortest distance
Codes are as follows:
import java.awt.Point;
double distance(Point p1, Point p2)
{
return Math.sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
}
int[] shortest_pair(Point[] coordinates)
{
int m = coordinates.length;
double shortest_distance = Double.MAX_VALUE;
int[] shortest_pair = new int[2];
for (int i = 0; i < m-1; i++)
{
for (int j = i+1; j < m; j++)
{
double d = distance(coordinates[i], coordinates[j]);
if (d < shortest_distance)
{
shortest_distance = d;
shortest_pair[0] = i;
shortest_pair[1] = j;
}
}
}
return shortest_pair;
}
Example is as follows:
Random rand = new Random();
rand.setSeed(0);
int m = coordinates.length;
assert m == 10;
for(int i = 0; i < m; i++)
coordinates[i] = new Point(rand.nextInt(10), rand.nextInt(10));
assert Arrays.equals(shortest_pair(coordinates), new int[] { 2, 7 });
I want to find the shortest path on a list of linked list, which represents a directed graph with cost per edge/path.
The output would look something like this, It tells me the cost it would take me to get from vertex 0 to the other vertices:
d[0 to 0] = 0
d[0 to 1] = 20
d[0 to 2] = 10
This is how I populate my list for testing.
LinkedList<GraphData> g = new LinkedList[3];
for (int i = 0; i < 3; i++)
weight[i] = new LinkedList<GraphData>();
g[0].add(new GraphData(1, 20);
g[0].add(new GraphData(2, 10);
The GraphData class looks something like this:
int vertex, int edgeCost;
Now for my problem:
I want to find the shortest path from vertex v to all the others.
public static int[] shortestPaths(int v, LinkedList<GraphData>[] cost)
{
// get the set of vertices
int n = cost.length;
// dist[i] is the distance from v to i
int[] dist = new int[n];
// s[i] is true if there is a path from v to i
boolean[] s = new boolean[n];
// initialize dist
for(int i = 0; i < n; i++)
dist[i] = cost[v].get(i).getCost();
s[v] = true;
// determine n-1 paths from v
for ( int j = 2 ; j < n ; j++ )
{
// choose u such that dist[u] is minimal for all w with s[w] = false
// and dist[u] < INFINITY
int u = -1;
for (int k = 0; k < n; k++)
if ( !s[k] && dist[k] < INFINITY)
// check if u needs updating
if ( u < 0 || dist[k] < dist[u])
u = k;
if (u < 0)
break;
// set s[u] to true and update the distances
s[u]=true;
for (int k = 0; k < n; k++)
if ( !s[k] && cost[u].get(k).getCost() < INFINITY )
if( dist[k] > dist[u] + cost[u].get(k).getCost())
dist[k] = dist[u] + cost[u].get(k).getCost();
// at this point dist[k] is the smallest cost path from
// v to k of length j.
}
return dist;
}
This line dist[i] = cost[v].get(i).getCost(); throws "IndexOutOfBoundsException"
Any idea what I am doing wrong? Any help will be appreciated.
There are two common ways to represent graphs: adjacency lists and adjacency matrices.
Adjacency List: Array of lists. The element at index i is a small list containing the outgoing edges of vertex i. This is what you are creating when you populate the list.
Adjacency Matrix: Array of arrays, with cost[i][j] containing the cost of the edge from vertex i to vertex j. You are using the cost parameter as if it is an adjacency matrix.
You have two options:
Change the graph construction to create an adjacency matrix and use an array of arrays
Change the algorithm to treat cost as an adjacency list instead of an adjacency matrix
Here is the second option. I renamed a few things and simplified the initialization so that the first iteration calculates the distance to the immediate neighbours of v (as opposed to doing it as a special case at the start).
import java.util.*;
public class Main
{
public static int[] shortestPaths(int v, LinkedList<Edge>[] edges)
{
// get the set of vertices
int n = edges.length;
// dist[i] is the distance from v to i
int[] dist = new int[n];
for (int i = 0; i < n; i++) {
dist[i] = Integer.MAX_VALUE;
}
// seen[i] is true if there is a path from v to i
boolean[] seen = new boolean[n];
dist[v] = 0;
// determine n-1 paths from v
for (int j = 0; j < n; j++) {
// choose closest unseen vertex
int u = -1;
for (int k = 0; k < n; k++) {
if (!seen[k]) {
// check if u needs updating
if (u < 0 || dist[k] < dist[u]) {
u = k;
}
}
}
if (u < 0 || dist[u] == Integer.MAX_VALUE) {
break;
}
// at this point dist[u] is the cost of the
// shortest path from v to u
// set seen[u] to true and update the distances
seen[u] = true;
for (Edge e : edges[u]) {
int nbr = e.getTarget();
int altDist = dist[u] + e.getCost();
dist[nbr] = Math.min(dist[nbr], altDist);
}
}
return dist;
}
public static void main(String[] args)
{
int n = 5;
int start = 0;
LinkedList<Edge>[] cost = new LinkedList[n];
for (int i = 0; i < n; i++) {
cost[i] = new LinkedList<Edge>();
}
cost[0].add(new Edge(1, 20));
cost[0].add(new Edge(2, 10));
cost[1].add(new Edge(3, 5));
cost[2].add(new Edge(1, 6));
int[] d = shortestPaths(start, cost);
for (int i = 0; i < n; i++) {
System.out.print("d[" + start + " to " + i + "] = ");
System.out.println(d[i]);
}
}
}
class Edge
{
int target, cost;
public Edge(int target, int cost) {
this.target = target;
this.cost = cost;
}
public int getTarget() {
return target;
}
public int getCost() {
return cost;
}
}
Probably element cost[v].get(i) does not exist (no element with index i in this LinkedList which is cost[v]).
http://docs.oracle.com/javase/6/docs/api/java/util/LinkedList.html#get(int)
The problem is that your indices do not correspond. If you only put one distance, for instance
cost[0].add(new GraphData(5, 20));
then
cost[0].get(5).getCost();
will throw an IndexOutOfBoundsException, because you should do
cost[0].get(0).getCost();
in order to get 20 (which is very confusing).
I would advise using a Map, rather than a List to encode the edge costs.
You populate that Map like
List<Map<Integer, Integer>> g = new ArrayList<>();
for (int i = 0; i < 3; i++)
g.add(new HashMap<Integer, Integer>());
g.get(0).put(1, 20);
g.get(0).put(2, 10);
With this, you could initialize your dist array like
// initialize dist
for(int i = 0; i < n; i++)
dist[i] = cost.get(v).containsKey(i) ? cost.get(v).get(i) : INFINITY;
I have an array (Arr). I fill points1 and points2 with values.
public class Arr {
float pointX;
float pointY;
boolean yesNo;
String text;
}
public Arr points1[];
public Arr points2[];
points1 = new Arr[100];
for (int i = 0; i < 100; i++) points1[i]= new Arr();
for (int j = 0; j < 100; j++) {
points1[j].pointX = getFloat;
points1[j].pointY = getFloat;
points1[j].yesNo = getBoolean;
points1[j].text = getText;
}
points2 = new Arr[100];
for (int x = 0; x < 100; x++) points2[x]= new Arr();
for (int y = 0; y < 100; y++) {
points2[y].pointX = getFloat;
points2[y].pointY = getFloat;
points2[y].yesNo = getBoolean;
points2[y].text = getText;
}
This works, but what is, when I have five of them or more (points1, points2, points3...)
How can I make "public Arr points[][]"? And then fill and get the values with e.g. points[0][22].pointX or points[1][10].text?
And how can I see the points[][] array like var_dump in PHP? How list the array?
var_dump example:
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(1) "c"
}
}
This is a working example
package com.stackoverflow.q15134193;
public class Test1 {
public static Arr[][] points;
static float getFloat = 1;
static boolean getBoolean = true;
static String getText = "hi";
public static void main(String[] args) {
points = new Arr[100][];
for (int i = 0; i < points.length; i++) {
points[i] = new Arr[100];
for (int j = 0; j < points[i].length; j++)
points[i][j] = new Arr();
}
for (int i = 0; i < points.length; i++) {
for (int j = 0; j < points[i].length; j++) {
points[i][j].pointX = getFloat;
points[i][j].pointY = getFloat;
points[i][j].yesNo = getBoolean;
points[i][j].text = getText;
}
}
for (int i = 0; i < points.length; i++)
for (int j = 0; j < points[i].length; j++)
System.out.println("X: " + points[i][j].pointX + " Y: "
+ points[i][j].pointY + " YesNo: "
+ points[i][j].yesNo
+ " text: "+ points[i][j].text);
}
}
class Arr {
public float pointX;
public float pointY;
public boolean yesNo;
public String text;
}
I'm not completely clear on what you're trying to achieve, but Java isn't PHP.
Java has an extensive set of Collections which will give you much better coverage then simple array's.
As I'm not completely sure what you're trying to do, I can't really tell you what collections could do the job, but you could read up on things like Maps and ArrayList.
You could make, per example an ArrayList of 'Arr's like
ArrayList<Arr> list = new ArrayList<Arr>();
Similarly you can do ArrayList<Arr, Arr>, or start working with Maps if you want to store your object Arr together with a key to find it with.
Once you're using a Java Collection, the clearest way to print these is just looping over it , with something like
for(Arr a : list){
Log.d("my_tag", "My list contains"+a.toString());
}
Instead of 2D array, you can use ArrayList.
ArrayList<Arr> points = new ArrayList<Arr>();
Now, access an index as following:
points.get(22).pointX OR points.get(10).text
Try to print the arraylist points, to see a near about string output:
System.out.println(points);
You need to implement a toString() method in your class Arr, and then call
Log.i("mytag", Arrays.toString(points1));
as explained here how see an array in logcat for android