小背景:
我的csv文件有很多行,每行都有字符串元素,这样一行的例子就是
String[] data = [20,11,Clothing,TShirts,Abercombie,Gap]
data.toString() = [Ljava.lang.String;@1152e94]
Run Code Online (Sandbox Code Playgroud)
现在在我的解析器中,我正在解析此csv文件并将每行存在于文件中
String[] data.在我的日志页面中,我需要id和文件中的行.
目前,如果我尝试打印然后得到像这样的值 [Ljava.lang.String;@1152e94,我的问题是如何获得数组元素的实际列表[20, 11, Clothing, TShirts, Abercombie, Gap]?
尝试使用默认toString()但仍然提供相同的LString数据.
对于PCG.SE上的这一挑战,需要编写一个返回/输出前N个素数的函数/程序.
但是,程序中不允许使用带有主要代码点的字符.
其中两个字符是5和e.两个字母的代码点都包含一个5.因此,\u{codepoint}这两封信不会起作用.
使用转义,我可以从代码中删除所有主要字符,除了ein return.
我可以使用System.out或者FileDescriptor.out都包含这封信e.
有没有办法返回或输出而不使用e或5?
这里的参考是我的代码与字符转义:
int[]b(int b\u0029{
int c,d,f[]\u003d{}\u003b
for(f\u003dj\u0061v\u0061.util.Arr\u0061ys.copy\u004ff(f,b\u0029\u003bb-->0\u003b\u0029
for(d\u003d0,c\u003d2\u003bf[b]<1\u003bf[b]\u003dd<1?c:f[b],d\u003d0,c\u002b\u002b\u0029
for(int h:f\u0029
d\u003dh>0&&c\u002fh*h\u003d\u003dc?1:d\u003b
return f;
}
Run Code Online (Sandbox Code Playgroud)
没有字符转义:
int[]b(int b){
int c,d,f[]={};
for(f=java.util.Arrays.copyOf(f,b);b-->0;)
for(d=0,c=2;f[b]<1;f[b]=d<1?c:f[b],d=0,c++)
for(int h:f)
d=h>0&&c/h*h==c?1:d;
return f;
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
private static final Logger logger = LoggerFactory.getLogger(Some.class);
...
String[] splits=someString.split("..");
logger.info("The string was split into <{}>",splits); // prints first element
Run Code Online (Sandbox Code Playgroud)
使用slf4j打印数组的完整内容的正确方法是什么?
我有一个字符串数组,其中包含我定义的四个元素.我怎么打字System.out.println(name of Array),它不输出元素?但反而给了我一个奇怪的输出.
这是我的代码......
public class GeniusTrial {
public static void main(String[]args) {
String [] genius = {"Einstein, ", "Newton, ", "Copernicus, ", "Kepler."};
System.out.print(genius);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出:
[Ljava.lang.String;@3e25a5
Run Code Online (Sandbox Code Playgroud) 我正在尝试将字符串转换为整数数组,以便我可以对它们执行数学运算.我在使用以下代码时遇到问题:
String raw = "1233983543587325318";
char[] list = new char[raw.length()];
list = raw.toCharArray();
int[] num = new int[raw.length()];
for (int i = 0; i < raw.length(); i++){
num[i] = (int[])list[i];
}
System.out.println(num);
Run Code Online (Sandbox Code Playgroud)
这给了我一个"不可转换的类型"错误,必需:int [] found:char我还尝试了一些其他的方法,如Character.getNumericValue,只是直接分配它,没有任何修改.在那些情况下,它总是输出相同的垃圾"[I @ 41ed8741",无论我使用什么转换方法或(!)字符串的实际值是什么.它与unicode转换有关吗?
我一直在尝试将数组写入文件.我知道如何将整数或字符串写入文件但是让数组混淆了我.我现在正在使用它:
public static void write (String file, int[]x) throws IOException{
BufferedWriter outputWriter = null;
outputWriter = new BufferedWriter(new FileWriter(filename));
outputWriter.write("hi");// Here I know i cant just write x[0] or anything. Do i need
//to loop in order to write the array?
outputWriter.newLine();
outputWriter.flush();
outputWriter.close();
}
Run Code Online (Sandbox Code Playgroud) 我有一串1和0,我想转换为字节数组.
例如,String b = "0110100001101001"如何将其转换byte[]为长度为2的?
为了理解某些代码的内部结构或错误的打印转储,我在Python和Emacs lisp中使用类似pp的函数.
现在我来到Java并寻找标准库或tecnique来获得OBJECT for Java的漂亮印刷表示.
似乎当前的Java规范允许在运行时内省Java对象.但内省可能不是那么强大.使用new Object [] arg 无法调用m(Object o)?
注意我不希望源代码美化!我正在寻找运行时漂亮的打印Java对象转储.
注2:这些问题相似但不完全相同:
我使用以下代码进行加密和解密,而解密时我在运行时收到错误。错误消息是“非法的 base64 字符 20”
加密代码:
String secretValue = "sazhwsxplokmeroo";
keyValue = secretValue.getBytes();
Key generatedKey = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.ENCRYPT_MODE, generatedKey);
byte[] encValue = c.doFinal(userEmail.getBytes());
String encryptedValue = Base64.getEncoder().encodeToString(encValue);
Run Code Online (Sandbox Code Playgroud)
密钥:
private Key generateKey() {
Key secretKey = new SecretKeySpec(keyValue, ALGO);
return secretKey;
}
Run Code Online (Sandbox Code Playgroud)
解密代码:
String secretValue = "sazhwsxplokmeroo";
keyValue = secretValue.getBytes();
Key generatedKey = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.DECRYPT_MODE, generatedKey);
byte[] decodedValue = Base64.getDecoder().decode(encryptEmail.getBytes()); //error throws from this line as illegal base64 character 20
byte[] decValue = c.doFinal(decodedValue); …Run Code Online (Sandbox Code Playgroud) 如何在Java中Array转换内容String?
例:
int[] myArray = {1,2,3};
Run Code Online (Sandbox Code Playgroud)
输出必须是:
"123"
Run Code Online (Sandbox Code Playgroud)
Arrays.toString(myArray) 正在回归:
"[1, 2, 3]"
Run Code Online (Sandbox Code Playgroud)
并且myArray.toString(),返回:
[I@12a3a380
Run Code Online (Sandbox Code Playgroud)
所以它们都不起作用.这有功能吗?
这个问题可能与(this)类似,但实际上是不同的.我真的要求一个由所有数组条目组成的String.