长类|番石榴|爪哇

渴望 是用于基本类型long的实用程序类。它提供 静态效用方法 用于修饰或说明long原语,在long或数组中都找不到。

null

宣言:

@GwtCompatible(emulated=true)
public final class Longs
extends Object

下表显示了番石榴长类的字段摘要:

图片[1]-长类|番石榴|爪哇-yiteyi-C++库 Guava Longs类提供的一些方法包括: 图片[2]-长类|番石榴|爪哇-yiteyi-C++库 例外情况:

  • 敏: 非法数据异常 如果数组为空。
  • 最大值: 非法数据异常 如果数组为空。
  • fromByteArray: 非法数据异常 如果字节少于8个元素。
  • 保证能力: 非法数据异常 如果minLength或padding为负数。
  • 今天: 空指针异常 如果集合或其任何元素为空。

下表显示了Guava Longs类提供的一些其他方法: 图片[3]-长类|番石榴|爪哇-yiteyi-C++库 下面给出了一些示例,展示了Guava Longs类方法的实现: 例1:

// Java code to show implementation
// of Guava Longs.asList() method
import com.google.common.primitives.Longs;
import java.util.*;
class GFG {
// Driver method
public static void main(String[] args)
{
long arr[] = { 3L, 4L, 5L, 6L, 7L };
// Using Longs.asList() method which wraps
// the primitive long array as List of
// long Type
List<Long> myList = Longs.asList(arr);
// Displaying the elements
System.out.println(myList);
}
}


输出:

[3, 4, 5, 6, 7]

例2:

// Java code to show implementation
// of Guava Longs.toArray() method
import com.google.common.primitives.Longs;
import java.util.*;
class GFG {
// Driver method
public static void main(String[] args)
{
List<Long> myList = Arrays.asList(3L, 4L, 5L, 6L, 7L);
// Using Longs.toArray() method which
// converts a List of Longs to an
// array of long
long [] arr = Longs.toArray(myList);
// Displaying the elements
System.out.println(Arrays.toString(arr));
}
}


输出:

[3, 4, 5, 6, 7]

例3:

// Java code to show implementation
// of Guava Longs.concat() method
import com.google.common.primitives.Longs;
import java.util.*;
class GFG {
// Driver method
public static void main(String[] args)
{
long [] arr1 = { 3L, 4L, 5L };
long [] arr2 = { 6L, 7L };
// Using Longs.concat() method which
// combines arrays from specified
// arrays into a single array
long [] arr = Longs.concat(arr1, arr2);
// Displaying the elements
System.out.println(Arrays.toString(arr));
}
}


输出:

[3, 4, 5, 6, 7]

例4:

// Java code to show implementation
// of Guava Longs.contains() method
import com.google.common.primitives.Longs;
class GFG {
// Driver method
public static void main(String[] args)
{
long [] arr = { 3L, 4L, 5L, 6L };
// Using Longs.contains() method which
// checks if element is present in array
// or not
System.out.println(Longs.contains(arr, 4L));
System.out.println(Longs.contains(arr, 7L));
}
}


输出:

true
false

例5:

// Java code to show implementation
// of Guava Longs.min() method
import com.google.common.primitives.Longs;
class GFG {
// Driver method
public static void main(String[] args)
{
long [] arr = { 3L, 4L, 5L, 6L };
// Using Longs.min() method
System.out.println(Longs.min(arr));
}
}


输出:

3

例6:

// Java code to show implementation
// of Guava Longs.max() method
import com.google.common.primitives.Longs;
class GFG {
// Driver method
public static void main(String[] args)
{
long [] arr = { 3L, 4L, 5L, 6L };
// Using Longs.max() method
System.out.println(Longs.max(arr));
}
}


输出:

6
© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享