Code:int[] array; int sum = IntStream.of(array).sum();
|
In the current class i can't make new instances of the class. I am reading numbers from a website currently and want to make each number an integer returned in a getInt method of some kind... Like i said i can't loop through the class i'm referencing but i need to add the id's from the website as Integers but the only way i can think of doing it is getting the numbers from the website and adding it to an int[] array but there is no way to make it get all the values without looping or i need it to get all the values in a getInt method that breaks the int[] array down and the return be each separate integer to see if it works. Thanks in advance if you can help me with the getInt from the int[] (must be an int[] because many id's being read)
That gives a sum of all numbers in an ArrayList. I need to make each integer in the arraylist it's own int for a class such as Thisclass suchandsuch = new Thisclass.getId(myarraylisthere)
but the arraylist but be an iteration of all id's in a separate format due to the fact i cant iterate through suchandsuch because Thisclass doesn't support being called multiple times so i need to get a method to convert the int array to individual ints for the constructor
SSCCE:
Code:public class MyClass { public int getId() { return 0; } public static void main(String[] args) throws Exception { MyClass[] classes = {}; // ... int sum = Arrays.stream(classes).mapToInt(MyClass::getId).sum(); } }Since I couldn't get what you're trying to do maybe either of these help. Try explaining with punctuation and a bit less ambiguity.Code:public class MyClass { MyClass(int i) { // initialize using i } public static void main(String[] args) { int[] values = {}; // ... MyClass[] classes = IntStream.of(values).mapToObj(MyClass::new).toArray(MyClass[]::new); } }
the guy is clearly just trying to use technical terms while having no real idea of what they mean. doesn't really make him 'retarded' though.
OP used Confusion.
It's super effective!
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |