Checking Java Collection Generic Type for an Empty Collection

前端 未结 4 1651
情话喂你
情话喂你 2021-01-15 05:56

I want to implement the following function:

public boolean checkType(Vector vec)
{
  // return true if its Vector and false otherwise         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-15 06:41

    public boolean checkType(Vector vec)
    {
      if(!vec.isEmpty())
      {
        if("String".equals(vec.get(0).getClass().getSimpleName()))
                 return false;
        else if("Integer".equals(vec.get(0).getClass().getSimpleName()))
                 return true;               
       }
    }
    

    Hope this helps!!

提交回复
热议问题