Thread: Int[] to int without loop

Page 1 of 2 12 LastLast
Results 1 to 10 of 19
  1. #1 Int[] to int without loop 
    Donator

    Join Date
    Mar 2011
    Posts
    118
    Thanks given
    3
    Thanks received
    5
    Rep Power
    1
    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)
    Reply With Quote  
     

  2. #2  
    Bossman

    ISAI's Avatar
    Join Date
    Sep 2012
    Posts
    1,916
    Thanks given
    655
    Thanks received
    1,366
    Rep Power
    5000
    Code:
    int[] array; 
    int sum = IntStream.of(array).sum();
    Reply With Quote  
     

  3. #3  
    Donator

    Join Date
    Mar 2011
    Posts
    118
    Thanks given
    3
    Thanks received
    5
    Rep Power
    1
    Quote Originally Posted by ISAI View Post
    Code:
    int[] array; 
    int sum = IntStream.of(array).sum();
    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
    Reply With Quote  
     

  4. #4  
    Bossman

    ISAI's Avatar
    Join Date
    Sep 2012
    Posts
    1,916
    Thanks given
    655
    Thanks received
    1,366
    Rep Power
    5000
    If you give me a code example of your current work I could give more help.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Velocity's Avatar
    Join Date
    Jan 2009
    Age
    28
    Posts
    2,028
    Thanks given
    1,013
    Thanks received
    2,376
    Rep Power
    4112
    Quote Originally Posted by cardnal009 View Post
    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();
    	}
    }
    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);
    	}
    }
    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.
    xxxxxxx
    Reply With Quote  
     

  6. #6  
    Registered Member
    hacker's Avatar
    Join Date
    Jun 2013
    Posts
    1,409
    Thanks given
    576
    Thanks received
    580
    Rep Power
    5000
    what the fuck did i just read

    Quote Originally Posted by cardnal009 View Post
    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
    array list? weren't we talking about int arrays
    Attached image
    Reply With Quote  
     

  7. Thankful user:


  8. #7  
    Registered Member
    Velocity's Avatar
    Join Date
    Jan 2009
    Age
    28
    Posts
    2,028
    Thanks given
    1,013
    Thanks received
    2,376
    Rep Power
    4112
    After trying to decompose OP's question I have come to the conclusion OP is retarded.
    xxxxxxx
    Reply With Quote  
     

  9. Thankful users:


  10. #8  
    Registered Member
    hacker's Avatar
    Join Date
    Jun 2013
    Posts
    1,409
    Thanks given
    576
    Thanks received
    580
    Rep Power
    5000
    Quote Originally Posted by Velocity View Post
    After trying to decompose OP's question I have come to the conclusion OP is retarded.
    Lol I read what he said over and over and over again. I didnt even want to help him, I just wanted to understand what he was trying 2 say.
    Attached image
    Reply With Quote  
     

  11. #9  
    Registered Member
    Join Date
    Apr 2016
    Posts
    124
    Thanks given
    14
    Thanks received
    21
    Rep Power
    37
    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.
    Reply With Quote  
     

  12. #10  
    Registered Member
    whac's Avatar
    Join Date
    Nov 2011
    Posts
    176
    Thanks given
    35
    Thanks received
    84
    Rep Power
    245
    OP used Confusion.

    It's super effective!
    Reply With Quote  
     

  13. Thankful user:


Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. need some help, with int[] to int
    By jelleplomp in forum Help
    Replies: 7
    Last Post: 05-05-2015, 05:21 PM
  2. private void objectToRemove3(int X, int Y, int h) {
    By Ninja assassin in forum Help
    Replies: 8
    Last Post: 11-07-2010, 12:18 AM
  3. int to minutes
    By Nour in forum Snippets
    Replies: 17
    Last Post: 01-05-2009, 10:55 AM
  4. A simple int to minutes converter
    By Nour in forum Tutorials
    Replies: 20
    Last Post: 01-05-2008, 11:09 PM
  5. Writing a int to character files
    By Eternal Darknes in forum Tutorials
    Replies: 7
    Last Post: 11-30-2007, 05:55 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •