How to access the elements of a two-dimensional collection?

Hello!
Made it a two-dimensional collection. Here it is:
public class Collection {
 ArrayList<ArrayList<Integer>> collectionOfPoints;
 ArrayList<Integer> subCollectionOfPoints;
 int x, y;
 public Collection(){
 collectionOfPoints = new ArrayList(); 
 x = 0;
 y = 0;
}
 public void calculatePoints(){
 for(int i = 0; i < 10; i++){
x++;
y++;
 subCollectionOfPoints = new ArrayList<Integer>();
subCollectionOfPoints.add(x);
subCollectionOfPoints.add(y);
collectionOfPoints.add(subCollectionOfPoints);
}
 System.out.println("the Collection of points created!");

}
 public ArrayList returnCallOfPoints(){
 return collectionOfPoints;
}
}


In short, it's simple. Is a collection of collections, each of which contains a pair of points. Everything works, it prints out as it should and all that.

if(ОбъектКлассаСРеализациейДвумернойколлекции.returnCallOfPoints().size() != 0){
System.out.println(ОбъектКлассаСРеализациейДвумернойколлекции.returnCallOfPoints().get(1));
 }


The result is in the console [2, 2], which is logical.
I just need to refer to the second or the first value in the nested collection. Logic dictates that I should write something like this:
System.out.println(ОбъектКлассаСРеализациейДвумернойколлекции.returnCallOfPoints().get(1).get(1));

But, the designers of Java apparently logic was different from mine(Bless them Lord).
How to do it?
March 23rd 20 at 19:05
1 answer
March 23rd 20 at 19:07
Solution
I will not explain that it would be more correct to call it an integer matrix, it is not necessary to give the class the name of the standard interface and much more...
Well, what's the issue then?
In principle, the right argue...
Only it is not necessary to return the inside.
better make it a setter/getter, where you check for vozmozhnye mistakes, etc.
type
GetValueByIndexies Integer(int x, int y){
//any inspections that there was no uncontrolled accessnow, like outofrange
return collectionOfPoints.get(x).get(y);
}
the class name was stupid, changed in the course of writing the question:DD - fabiol commented on March 23rd 20 at 19:10
In short, I have Wednesday swears by get().get()
Does not compile anything
Do not understand what
Probably some troubles with the versions of the language and all that.
How to solve it? - fabiol commented on March 23rd 20 at 19:13
get().get () is quite normal. And version almost exactly....
But yet the entire code and its use, that is anyone's guess...
At least what the error says?(But not specific working code would be better...) - nikolas.Moscis commented on March 23rd 20 at 19:16
@nikolas.Moscis, generally the second Wednesday seems get red, like th want no such function in the first return getом object
but when compiling gives the same, only in English
error: cannot find symbol method get(int) - fabiol commented on March 23rd 20 at 19:19
@nikolas.Moscis,
It's weird, because I have
subCollectionOfPoints = new ArrayList<Integer>();
collectionOfPoints.add(subCollectionOfPoints);

the collection hits collection... - fabiol commented on March 23rd 20 at 19:22
All... Dumb... Not write so this is the style 5-6 Java, I don remember exactly... always the type to try to specify...
You have a method
public ArrayList returnCallOfPoints(){
return collectionOfPoints;
}
Wrong in the same place for 2 reasons...
First... the higher the abstraction, the better(then you will understand why, either with experience or Sauli)
And secondly... public ArrayList methodName(){}
Means that will return you an ArrayList
Ie
Or right to make a public List> returnCallOfPoints(){...}
Or
System.out.println(
((ArrayList) (ОбъектКлассаСРеализациейДвумернойколлекции
.returnCallOfPoints()
.get(1))
).get(1)
);


Something like that... Maybe sealed but the idea is correct and mistake in this... - nikolas.Moscis commented on March 23rd 20 at 19:25
Hmm, sealed and stupid... Sori...
And secondly... public ArrayList methodName(){}
Means that will return you an Object
For ArrayList == ArrayList - nikolas.Moscis commented on March 23rd 20 at 19:28
Understand... angle brackets, they devour...
Attempt No. 3( spaces before and after parentheses)
Means that will return you an Object
For ArrayList == ArrayList < Object > - nikolas.Moscis commented on March 23rd 20 at 19:31
@fabiol,
Hmm... this siyaniem brackets Faile turned out...

public List< List < Integer > > returnCallOfPoints(){...}
- nikolas.Moscis commented on March 23rd 20 at 19:34
@nikolas.Moscis, Thank you dear man HUGE =*
Everything worked as it should! - fabiol commented on March 23rd 20 at 19:37

Find more questions by tags Java