Tag: 字符串

调用一个mysql函数在hibernate中返回varchar

我试图在hibernate中使用mysql find_in_set字符串函数但不幸的是我无法使用它甚至尝试通过创建这些寄存器函数 registerFunction(“findInSet”,newSQLFunctionTemplate(Hibernate.STRING,”FIND_IN_SET(?1,?2)”)); registerFunction(“findInSet”,newSQLFunctionTemplate(Hibernate.INTEGER,”FIND_IN_SET(?1,?2)”)); registerFunction(“findInSet”,new StandardSQLFunction(“find_in_set”, Hibernate.INTEGER)); 使用mysqldialect但没有人工作..任何人请告诉我如何在hibernate中使用mysql字符串函数。 或对上述寄存器function的任何更改。 提前致谢, 最诚挚的问候,拉贾。

为什么String不需要新的关键字

我是java的新手。 在java中, String是一个class 。但是我们不必使用new关键字来创建类String的对象,其中new用于为其他类创建对象。 我听说过类似于Integer , Double Wrapper类。 但String不是Wrapper,不是吗? 实际上当我使用时发生了什么 String message = “Hai”; ?? 它有什么不同 String message = new String(“Hai”); 这是message引用变量还是其他什么? 还有其他类不需要new来创建对象吗?

Java Compiler是否包含String Constant Folding?

我发现Java支持原始类型的常量折叠 ,但是String呢? 例 如果我创建以下源代码 out.write(“” + “” + “” + “Easier to read if it is split into multiple lines” + “” + “” + “”); 什么进入编译代码? 合并版? out.write(“Easier to read if it is split into multiple lines”); 或者效率较低的运行时级联版本? out.write(new StringBuilder(“”).append(“”).append(“”).append(“Easier to read if it is split into multiple lines”).append(“”).append(“”).append(“”));

Java,检查String是否是回文。 不区分大小写

我想编写一个java方法,如果字符串是回文,则返回true。 这是我到目前为止: String palindrome = “…”; boolean isPalindrome = palindrome.equals( new StringBuilder(palindrome).reverse().toString()); 我的问题在于它没有考虑这样一个词: Race car是一个回文。 Doc, note, I dissent. A fast never prevents a fatness. I diet on cod. 测试这是否是回文的最佳方法是什么,不区分大小写并忽略标点符号。

在Java中将毫秒字符串转换为日期

我有一个字符串x =“1086073200000”。 这基本上是毫秒,我需要转换为Date。 转换我正在使用 DateFormat formatter = new SimpleDateFormat(“dd/MM/yyyy”); long tempo1=Long.parseLong(x); System.out.println(tempo1); // output is 86073200000 instead of the whole thing long milliSeconds=1346482800000L; Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milliSeconds); System.out.println(formatter.format(calendar.getTime())); 问题是当我将字符串x转换为long时,由于long的大小限制,一些数字会消失。 如何保留整个String。 谢谢。

读取字符串next()和nextLine()Java

问题是当我尝试拆分(.split“”)每个空格时,我无法用next()原因读取变量输入,然后数组只得到我输入的前两个单词,所以我不得不使用keyboard.nextLine()和分裂过程的工作方式应该工作,我得到数组中的所有单词,但问题是,如果我使用nextLine()然后我必须创建另一个键盘对象来读取第一个变量(答案),这是唯一的方法我可以让它在这里工作是代码 Scanner keyboard=new Scanner(System.in); Scanner keyboard2=new Scanner(System.in);//just to make answer word int answer=keyboard.nextInt();//if I don’t use the keyboard2 here then the program will not work as it should work, but if I use next() instead of nextLine down there this will not be a problem but then the splitting part is a problem(this variable counts […]

如何计算元音和辅音,并在使用方法和返回结果输出时将字符串中的第一个字母大写

如果用户输入一个字符串: hello there 它应该输出 Hello has 2 vowels There has 3 consonants. 我知道这是一个相当简单的代码但是我得到了太多的想法并且感到困惑。 我需要一个确保我有2个numberofVowels和capitalizeWord的方法,并且都返回一个结果 我得到一个错误,我仍然试图在计算元音工作后想出来大写 import java.util.Scanner; public class Hwk9 { public static void main (String args[]) { Scanner stdin = new Scanner(System.in); String string1; System.out.println(“Enter a string”); string1 = stdin.nextLine(); string1 = string1.toLowerCase(); } public static int numberVowels(String string1) { int count = 0; […]

Java 8查找并替换匹配的字符串

我试图在errorMessage messages.properties中找到一个字符串,如果errorMessage有字符串我需要用相应的值替换它 我有messages.properties如下 inv_date=INVOICE DATE inv_id=INVOICE NUMBER cl_id=CLIENT ID lf_matter_id=LAW FIRM MATTER ID inv_total_net_due=INVOICE TOTAL (inv_start_date|invoice start date)=BILLING START DATE (inv_end_date|invoice end date)=BILLING END DATE inv_desc=INVOICE DESCRIPTION units=LINE ITEM NUMBER OF UNITS discount_amount=LINE ITEM ADJUSTMENT AMOUNT total_amount=LINE ITEM TOTAL (charge_date|charge date)= LINE ITEM DATE acca_task=LINE ITEM TASK CODE acca_expense=LINE ITEM EXPENSE CODE acca_activity= LINE ITEM […]

使用Java中特殊字符之前的转义替换特殊字符

在我的java代码中,如果一个字符串输入有任何提到的特殊字符,那么前面应该有\\ 特殊字符集是{+, -, &&, ||, !, (, ), {, },[, ], ^, “”, ~, *, ?, :, \} 。 我尝试使用String.replaceAll(old,new)但令我惊讶的是它不起作用,即使我为’old’和’new’提供了正确的值。 if old=”:”,new=”\:” 我将特殊字符放在一个String数组中,在for循环中迭代它,检查它是否存在于字符串中,如果是,则input.replaceAll(“:”,”\\:”) 。 但它没有给我预期的输出。 请帮忙 String[] arr = { “+”, “-“, “&&”, “||”, “!”, “(“, “)”, “{“, “}”, “[“, “]”, “^”, “\””, “~”, “*”, “?”, “:”, “\\”, “AND”, “OR” }; for (int i = […]

如何在Java中提取多项式系数?

以字符串-2x^2+3x^1+6为例,如何从存储在字符串中的等式中提取-2和6 ?