java面试题网

普通会员

483

帖子

9

回复

187

积分

楼主
发表于 2019-08-26 15:24:39 | 查看: 5063| 回复: 0

Guava Chars类

Guava Chars类

Chars是基本char类型的实用工具类。

类声明

以下是com.google.common.primitives.Chars类的声明:

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

字段

Guava Chars类_www.wityx.com

方法

Guava Chars类_www.wityx.com

方法继承

这个类从以下类继承的方法:

java.lang.Object

Chars 例子

选择使用任何编辑器创建以下java程序在 C:/> Guava GuavaTester.java

import java.util.List;
import com.google.common.primitives.Chars;

public class GuavaTester {
   public static void main(String args[]){
      GuavaTester tester = new GuavaTester();
      tester.testChars();
   }

   private void testChars(){
      char[] charArray = {a,b,c,d,e,f,g,h};

      //convert array of primitives to array of objects
      List<Character> objectArray = Chars.asList(charArray);
      System.out.println(objectArray.toString());

      //convert array of objects to array of primitives
      charArray = Chars.toArray(objectArray);
      System.out.print("[ ");
      for(int i = 0; i< charArray.length ; i++){
         System.out.print(charArray[i] + " ");
      }
      System.out.println("]");
      //check if element is present in the list of primitives or not
      System.out.println("c is in list? "+ Chars.contains(charArray, c));

      //return the index of element
      System.out.println("c position in list "+ Chars.indexOf(charArray, c));

      //Returns the minimum		
      System.out.println("Min: " + Chars.min(charArray));

      //Returns the maximum		
      System.out.println("Max: " + Chars.max(charArray));	
   }
}

验证结果

使用javac编译器编译如下类

C:Guava>javac GuavaTester.java

现在运行GuavaTester看到的结果

C:Guava>java GuavaTester

看到结果

[a, b, c, d, e, f, g, h]
[ a b c d e f g h ]
c is in list? true
c position in list 2
Min: a
Max: h


文章来自www.wityx.com,转载请注明出处!原文地址http://www.wityx.com/post/1267_1_1.html


java面试题交流群:327440556

上一篇:Guava Booleans类 下一篇:Guava Doubles类
您需要登录后才可以回帖 登录 | 立即注册

java面试题网www.wuliaokankan.cnjava建站系统提供技术支持V2.1 网站地图 © 2016-2018