Skip to content
Advertisement

Tag: integer

Convert a list of integers into a comma-separated string

I was trying to convert a list of Integers into a string of comma-separated integers. Collectors.joining(CharSequence delimiter) – Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order. I am getting an error in line number 8: The method collect(Collector<? super Integer,A,R>) in the type Stream is not applicable for the arguments (Collector<CharSequence,capture#20-of ?,String>)

How to check if a string is ‘float’ or ‘int’

I have a string, and I know that it only contains a number. How can I check if this number is int or float? Answer There are many ways to solve your problem. For example, you can use try{}catch(){}: Solution 1 Solution 2 Or you can use regex [-+]?[0-9]*.?[0-9]+: For more details, take a look at Matching Floating Point Numbers

Is there a default type for numbers in Java

If I write something like this Which type has the ’18’? Is it int or byte? Or doesn’t it have a type yet? It can’t be int, because something like this is correct: And this is incorrect: EDIT: I think I found the right part in the spec at Assignment Conversion : The compile-time narrowing of constants means that code

String.valueOf(Integer) always return 1

I’m trying to parse String “2 2 2” and add every symbol ‘2’ in ArrayList. This is my code: I can’t understand why System.out.println(String.valueOf(myIntArray.get(rawSize)));always return 1 ? UPDDATE: I try read file, which contain next text: Here is my Main function: public static void main(String[] args){ My output: When i replace:a_char = line.charAt(charCounter); with a_char = ‘5’;, my output: Can’t

Sum with Integer object if not null

I do not know if it is possible in Java but I need a method to do a special “add function”. Let me explain, SHORT VERSION: Is it possible to add an int with an Integer object? I need a method to check if that integer object exists, and add 0 if the object is null, add the correct value

Advertisement