if(input.charAt(i) == '0' || input.charAt(i) == '1' || input.charAt(i) == '2') {
}
是否有条件将其浓缩?或者没有?
答案 0 :(得分:3)
您可以检查字符是否与公用String
中的任何索引匹配。喜欢,
if ("012".indexOf(input.charAt(i)) > -1) {
}
答案 1 :(得分:2)
也许可读性更高(在Java 9+中)
cordova.InAppBrowser.open('https://xxx.blob.core.windows.net/files/yyy.octet-stream?sv=2018-03-28&sr=b&sig=y3Ls1wUesmq8xS9pvcBU%2BFsf9rMpYxGSaA%2BJno9e5Ik%3D&se=2020-03-03T09%3A08%3A02fZ&sp=r', '_blank', 'location=yes');
答案 2 :(得分:0)
您可以通过在变量中分配字符查找结果来使其更短( )(但仍然要进行三个相等性检查)。
scala> df2.columns
res39: Array[String] = Array(mpg, cyl, displ, hp, weight, accel, yr, origin, name, Rank)
// note here, you would use columns.slice with the indices for
// the columns you need, i.e. (1, 7)
val exprs = for (col <- df2.columns.slice(0, 8)) yield expr(s"first(${col}) as ${col}")
exprs: Array[org.apache.spark.sql.Column] = Array(first(mpg, false) AS `mpg`, first(cyl, false) AS `cyl`, first(displ, false) AS `displ`, first(hp, false) AS `hp`, first(weight, false) AS `weight`, first(accel, false) AS `accel`, first(yr, false) AS `yr`, first(origin, false) AS `origin`)
scala> val resultDF = df2.groupBy("name").pivot("Rank").agg(exprs(0), exprs.slice(1, exprs.length):_*)
scala> resultDF.columns
res40: Array[String] = Array(name, 1_mpg, 1_cyl, 1_displ, 1_hp, 1_weight, 1_accel, 1_yr, 1_origin, 2_mpg, 2_cyl, 2_displ, 2_hp, 2_weight, 2_accel, 2_yr, 2_origin, 3_mpg, 3_cyl, 3_displ, 3_hp, 3_weight, 3_accel, 3_yr, 3_origin, 4_mpg, 4_cyl, 4_displ, 4_hp, 4_weight, 4_accel, 4_yr, 4_origin, 5_mpg, 5_cyl, 5_displ, 5_hp, 5_weight, 5_accel, 5_yr, 5_origin, 6_mpg, 6_cyl, 6_displ, 6_hp, 6_weight, 6_accel, 6_yr, 6_origin, 7_mpg, 7_cyl, 7_displ, 7_hp, 7_weight, 7_accel, 7_yr, 7_origin, 8_mpg, 8_cyl, 8_displ, 8_hp, 8_weight, 8_accel, 8_yr, 8_origin, 9_mpg, 9_cyl, 9_displ, 9_hp, 9_weight, 9_accel, 9_yr, 9_origin, 10_mpg, 10_cyl, 10_displ, 10_hp, 10_weight, 10_accel, 10_yr, 10_origin)
您可以查看其他答案,例如创建Set / Array并执行 contains 检查是否将来相等检查的次数会增加。海事组织,应照原样写三张支票。