Posts

Showing posts with the label char

How best to determine if a String contains only null characters?

5 1 What's the right way to check if a string contains null characters only? String s = "\u0000"; if(s.charAt(0) == 0) { System.out.println("null characters only"); } Or String s = "\0\0"; for(int i = 0; i < s.length(); i++) { if(s.charAt(i) == 0) continue; else break; } Both work. But is there a better and more concise way to perform this check. Is there a utility to check if a string in java contains only null characters( \u0000 OR \0 ) ? And what is the difference between '\0' and '\u0000' ? java string java-8 char null-character ...

What is the purpose of a unary “+” before a call to std::numeric_limitsmembers?

I saw this example in cppreference's documentation for std::numeric_limits #include <limits> #include <iostream> int main() { std::cout << "type\tlowest()\tmin()\t\tmax()\n\n"; std::cout << "uchar\t" << +std::numeric_limits<unsigned char>::lowest() << '\t' << '\t' << +std::numeric_limits<unsigned char>::min() << '\t' << '\t' << +std::numeric_limits<unsigned char>::max() << '\n'; std::cout << "int\t" << std::numeric_limits<int>::lowest() << '\t' << std::numeric_limits<int>::min() << '\t' << std::numeric_limits<int>::max() << '\n'; std::cout << "float\t" << std::numeric_limits<float>::lowest() << '\t' << std::numeric_limits<float>::min() << '\t' << st...