Tag: 字符串

有效的Unicode字符串可以包含FFFF吗? Java / CharacterIterator坏了吗?

以下是java.text.CharacterIterator文档的摘录: 该interface定义了用于文本双向迭代的协议。 迭代器迭代有界字符序列。 […]方法previous()和next()用于迭代。 如果[…]它们返回DONE ,表示迭代器已到达序列的末尾。 static final char DONE :迭代器到达文本的结尾或开头时返回的常量。 值为\uFFFF ,“非字符”值不应出现在任何有效的Unicode字符串中 。 斜体部分是我无法理解的部分,因为从我的测试来看,它看起来像Java String肯定包含\uFFFF ,并且它似乎没有任何问题,除了显然使用规定的CharacterIterator遍历由于误报而中断的成语(例如, next()返回’\uFFFF’ == DONE当它没有真正“完成”时)。 这里有一个片段来说明“问题”( 另见ideone.com ): import java.text.*; public class CharacterIteratorTest { // this is the prescribed traversal idiom from the documentation public static void traverseForward(CharacterIterator iter) { for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) […]

如何在Java中反转String的大小写?

我想更改一个String,以便所有大写字符变为小写,并且所有小写字符变为大写。 数字字符只是被忽略。 所以“AbCdE123”变成“aBcDe123” 我想必须有一种方法来遍历String并翻转每个字符,或者可能是一些可以做到的正则表达式。

在Java中删除部分字符串

我想从一个字符中删除一部分字符串,即: 源字符串: manchester united (with nice players) 目标字符串: manchester united

Java字符串文字串联

public static void main(String[] args){ one(); two(); three(); } public static void one() { String s1 = “hill5”; String s2 = “hill” + 5; System.out.println(s1==s2); } public static void two() { String s1 = “hill5”; int i =5; String s2 = “hill” + i; System.out.println(s1==s2); } public static void three() { String s1 = “hill5”; […]

在Java中提取两个字符串之间的差异

嗨我有两个字符串: String hear = “Hi My name is Deepak” + “\n” + “How are you ?” + “\n” + “\n” + “How is everyone”; String dear = “Hi My name is Deepak” + “\n” + “How are you ?” + “\n” + “Hey there \n” + “How is everyone”; 我想得到听到的字符串中没有的内容“Hey There \ n”。 我找到了一个方法,但在这种情况下它失败了: static […]

在String中提取整数部分

提取字符串的整数部分的最佳方法是什么 Hello123 你如何获得123部分。 您可以使用Java的Scanner来破解它,有更好的方法吗?

是使用(“”+ )转换为String的不良做法?

是使用Java转换为String “” + 不好的做法? 与String.valueOf(…)相比,它有任何缺点吗? 代码示例: int i = 25; return “” + i; VS: int i = 25; return String.valueOf(i); 更新:(来自评论) 那么Integer.toString(int i)与String.valueOf(…)相比呢?

Java字符串实习生和文字

以下两段代码是否相同? String foo = “foo”; String foo = new String(“foo”).intern();

String类型中的方法格式(String,Object )不适用于参数(…)

这是我的代码: int hoursFormat = 1, minsFormat = 2, secsFormat = 3; String timeFormat = String.format(“%02d:%02d:%02d”,hoursFormat, minsFormat, secsFormat); 这给出了编译错误: Unresolved compilation problem: The method format(String, Object[]) in the type String is not applicable for the arguments (String, int, int, int) 为什么我在这里收到此错误,如何解决?

使用System.out.println显示特殊字符

我在使用Web服务中的特殊字符向我的数据库发送或显示文本时遇到问题。 在我的日食中,我将字符编码设置为UTF-8,但它仍然不允许我显示字符。 例如,简单的打印,如下面的代码 String test =”привет”; System.out.println(test); 要么 String test =”привет”; String query = “insert into communication (`test`) VALUES (‘”+ test +”‘); PreparedStatement preparedStmt1 = con.prepareStatement(query); preparedStmt1.executeUpdate(); 控制台上的结果以及如果我将其发送到我的数据库是??????。 如何在控制台上正确显示它并希望在数据库中显示