switch语句作用在byte上却不能作用在String和long上

2023-05-16

在switch(exprl)语句中,exprl必须是一个整数表达式或者枚举常量。而byte short char都可以隐式转换为int类型,整数表达式可以是int或者包装类Integer,所以byte short char类型是可以的。但是long String类型无法隐式转换为int,自身也不符合switch的语法规定。在JDK1.7之后引入新特性,switch语句可以作用在String上。
JAVA枚举一般是一组有关联的常量组成的集合,是一种特殊的数据类型,也可以理解为一个简洁的类,在JAVA中我们可以用enum声明一个枚举类型。## switch语句的运用

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

switch语句作用在byte上却不能作用在String和long上 的相关文章

  • 如何反转字符串中的单词但将标点符号保留在正确的位置? [复制]

    这个问题在这里已经有答案了 我编写了以下代码来反转输入字符串 Scanner s new Scanner System in System out println Please enter a sentence String sentenc
  • 在 Python 中对非英语文本进行分词

    我有一个波斯语文本文件 其中包含如下几行 6 7 10 11 我想从这一行生成一个单词列表 对我来说 单词边框是数字 比如上面一行中的 6 7 等 还有 特点 所以列表应该是 我想在 Python 3 3 中执行此操作 最好的方法是什么 我
  • 通过删除连续的重复项来减少字符串长度

    我有一个包含 2 个字段的 R 数据框 ID WORD 1 AAAAABBBBB 2 ABCAAABBBDDD 3 我想通过仅保留字母而不是重复中的重复项来简化具有重复字母的单词 e g AAAAABBBBB应该给我AB and ABCAA
  • 删除字符串 C 的第一个字符

    我试图删除字符串的第一个字符并保留其余部分 我当前的代码无法编译 我对如何修复它感到困惑 My code char newStr char charBuffer int len strlen charBuffer int i 1 char
  • 替换 JSON 中的转义字符

    我想用空格替换 JSON 字符串中的 字符 我怎样才能做到这一点 我发现从 JSON 字符串中删除所有转义字符的最简单 最好的方法是将字符串传递到正则表达式 Unescape 方法 此方法返回一个没有转义字符的新字符串 甚至删除了 n t
  • 在 pandas 数据框中使用 Replace 和 str.startswith() 来重命名值

    我有一个名为 源 的列 其中包含数百行文本 问题是 其中一些可以组合在一起 而我正在努力在 Pandas 数据框中做到这一点 这是我的代码 df source replace df source str startswith share n
  • string.split("(?!^)") 解释

    我正在尝试将字符串的字符拆分为字符串数组 我找到了解决方案here https stackoverflow com questions 5235401 split string into array of character strings
  • boost::algorithm::join 的一个很好的例子

    我最近想用提升 算法 加入 http www boost org doc libs 1 41 0 doc html string algo reference html header boost algorithm string join
  • 如何在 C++ 中将 CString 转换为 double?

    我如何转换CString to a double在 C 中 Unicode 支持也很好 Thanks A CString可以转换为LPCTSTR 这基本上是一个const char const wchar t 在 Unicode 版本中 知
  • libxml2 xmlChar * 到 std::wstring

    libxml2似乎将所有字符串存储在 UTF 8 中 如xmlChar xmlChar This is a basic byte in an UTF 8 encoded string It s unsigned allowing to pi
  • 如何从 PHP 中的字符串创建可能的字符串组合?

    如何从 PHP 中的字符串创建可能的字符串组合 Exp input abc output array 0 gt a 1 gt ab 2 gt abc 3 gt ac 4 gt acb 5 gt b 6 gt ba 7 gt bac 8 gt
  • R:根据元素长度从向量中删除元素

    如何根据字符串的字符数或长度从字符串向量中删除元素 df lt c asdf fweafewwf af aewfawefwef awefWEfawefawef gt df 1 asdf fweafewwf af aewfawefwef aw
  • 如何在字符串vba中包含引号

    我想存储以下文本 Test1 Monday Test Abcdef 全部在字符串中包含引号 我知道要在字符串中包含引号 我必须包含 之前 但在这里这不是一个很好的解决方案 因为我在文本中有太多这样的解决方案 知道如何一次完成这一切吗 您有两
  • 更改特定字符串的颜色

    有谁知道如果将特定单词输入文本区域 我如何更改它的颜色 例如 如果用户输入 你好我的朋友 它会动态地将 你好 更改为绿色 在google上花了很多时间 找不到任何相关的东西 谢谢 textareas 的设计目的不是选择性着色
  • Erlang:如何将原子转换为字符串?

    我想从原子转换为字符串 Input hello world Output hello world 我该如何实现这一目标 Use atom to list http erlang org doc man erlang html atom to
  • 从另一列的子字符串创建列

    我有一个 Pandas 数据框对象 我想从现有列的子字符串创建新列 我的数据如下所示 Date variable want1 want2 want3 0 02 01 08 Australia Sydney A Australia Sydne
  • NHibernate 获取 & 字符串 Id

    我在 NHibernate 上有一个分配了字符串 Id 的实体 并且在通过 Id 获取实体时遇到了一些问题 例子 假设有这样的数据库记录 Id Description AAA MyDescription 现在 如果我使用搜索 ID aaa
  • Swift:检查 UISearchBar.text 是否包含 url

    如何检查 UISearchBar text 是否包含 URL 我想做这样的事情 if searchBar text NSTextCheckingType Link 但我收到错误 String is not convertible to NS
  • toUpperCase() 方法什么时候创建一个新对象?

    public class Child public static void main String args String x new String ABC String y x toUpperCase System out println
  • 将字符串连接到python列表中所有元素的末尾

    我想知道如何将字符串连接到列表中所有元素的末尾 例如 List1 1 2 3 string a output 1a 2a 3a 在列表理解和使用中重建列表str format在两个参数上 gt gt gt string a gt gt gt

随机推荐

  • Laravel中间件向Controller传递值

    Laravel中间件向Controller传递值 方法一 span class token keyword class span MidParams span class token comment 中间件 span span class
  • 3. Proxmox VE 配置 NTP

    3 Proxmox VE配置 NTP 手动 span class token comment apt y install ntp span span class token comment vi etc ntp conf span span
  • 4. 在 Proxmox VE 安装Ceph

    4 在 Proxmox VE 安装 Ceph 1 安装 按图操作即可 2 参考 1 https blog csdn net ggeol article details 109112815
  • 5. 在 Proxmox VE 配置Ceph

    Pool 用于存储虚拟机的img xff0c 如果需要实现虚拟机的HA xff0c 那么虚拟机必须创建在Ceph上 xff0c 通过Ceph的多副本来实现故障恢复 CephFS 在PVE中主要用于共享文件 xff0c 如iso文件等 创建O
  • 6. Proxmox VE安装Ceph Dashboard

    6 Proxmox VE安装Ceph Dashboard span class token function apt get span span class token function install span ceph mgr dash
  • 7.安装Proxmox Backup Server

    安装Proxmox Backup Server 1 安装 安装和Proxmox VE基本是一样的 xff0c 看图一直下一步即可 安装完成会自动重启 xff0c 重启后如下图 2 参考 1 https pbs proxmox com wik
  • 8. 添加Backup Server到PVE集群

    添加Backup Server到PVE集群 1 配置磁盘 2 配置账户 3 PVE中添加 Backup Server
  • 在Harvester上安装windows sever 2012 r2

    安装Windows Server 2012 r2 文章目录 安装Windows Server 2012 r2新建虚拟机配置基础信息配置卷配置网络开机 xff0c 进入安装系统步骤安装磁盘驱动安装网络驱动安装其他驱动测试网络 Harveste
  • SDU 程序设计思维实践 第四周 csp模拟

    文章目录 题目A 咕咕东的奇遇题意InputOutput 思路总结代码 题目B 咕咕东想吃饭题意InputOutput 思路总结代码 题目C 可怕的宇宙射线题意InputOutput 思路总结代码 题目A 咕咕东的奇遇 题意 咕咕东是个贪玩
  • 使用MySQL8.0 by docker

    MySQL8 0 by Docker 拉取镜像 span class token function docker span pull mysql 8 0 为了获取到对应的配置文件而 docker run span class token f
  • 国内安装oh-my-zsh

    zsh有华丽的外表 xff0c 使用便捷的特点 xff0c 但在国内网络环境中 xff0c 安装会存在困难 xff0c 使用zsh官网提供的脚本安装 xff0c 基本会安装失败 xff0c 会显示报访问错误 xff0c 在此提供使用Git安
  • 使用kubeKey快速搭建Kubernetes集群

    使用kubeKey快速搭建Kubernetes集群 文章目录 使用kubeKey快速搭建Kubernetes集群一 安装 kk二 初始化本地主机 xff08 官方没写 xff09 三 安装集群3 1 All in One 测试集群无配置文件
  • 使用docker运行mysql-client

    使用docker运行mysql client 由于服务器环境的限制的 xff0c 能少污染主机环境就尽量不污染 xff0c 在集群环境 xff0c 使用docker运行mysql cli 访问通过NodePort暴露的数据库就是一个不错的方
  • CentOS 快速安装Docker

    CentOS 快速安装Docker 下载及安装 yum span class token function install span span class token function wget span y span class toke
  • 使用Docker快速搭建MSSQL实验环境 (持久化)

    使用Docker快速搭建MSSQL实验环境 xff08 持久化 xff09 前置章节 CentOS 快速安装Docker 使用Docker快速搭建MSSQL实验环境 拉取镜像 span class token function docker
  • 使用Docker快速搭建Oracle实验环境(持久化)

    容器镜像系统用户root密码为 helowin su root helowin 运行及配置 仅限测试环境 1 拉取镜像 span class token function docker span pull registry cn hangz
  • SHELL内涵段子

    1 字符掩码 xff0c 过滤掉不需要的 Database span class token assign left variable DATABASE MASK span span class token operator 61 span
  • Shell中读取文本文件

    读取文本文件 基础范式 span class token function cat span filename span class token operator span span class token keyword while sp
  • MySQL有点用的Shell片段

    获取Table Schema mysql span class token parameter variable uroot span p span class token variable passwd span span class t
  • switch语句作用在byte上却不能作用在String和long上

    在switch xff08 exprl xff09 语句中 xff0c exprl必须是一个整数表达式或者枚举常量 而byte short char都可以隐式转换为int类型 xff0c 整数表达式可以是int或者包装类Integer xf