Tag: 数组

Android:如何从这个json获取JSON对象键:

这是JSON数组: { “server_response”: [{ “Total”: “135”, “Paid”: “105”, “Rest”: “30” }] } 那么,我怎样才能获得对象名称? 我想把它们放在单独的TextView中。 谢谢。

查找数组中的整数模式

对于这个问题,我要编写一个名为mode的方法,它返回一个整数数组中最常出现的元素。 假设数组至少有一个元素,并且数组中的每个元素都具有0到100之间的值(包括0和100)。 通过选择较低的值来打破联系。 例如,如果传递的数组包含值{27,15,15,11,27},则您的方法应返回15.(提示:您可能希望查看本章前面的Tally程序以了解如何解决这个问题呢。) 我在查看特定输入的错误时遇到问题。 例如: 模式({27,15,15,27,11,11,11,14,15,15,16,19,99,100,0,27})返回15是正确的,但模式({1,1, 2,3,3}}当它应为1时返回3。 这是代码: public static int mode(int[] input) { int returnVal = input[0]; // stores element to be returned int repeatCount = 0; // counts the record number of repeats int prevRepCnt = 0; // temporary count for repeats for (int i=0; i<input.length; i++) { // goes through each […]

如何从文本文件中获取特定行到行并在android中显示数组列表

我有一个文本文件,我能够阅读完整的内容并将其显示在视图上。 文本文件的示例示例格式: – ## userdetail [William] [Bits] 6th cross road, City house. Rio. | ## calldetails income 22. out going 24. missed 21. ## Lorempsum Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took […]

java:读取文本文件并使用scanner类将信息存储在数组中

我有一个包含学生成绩的文本文件: Kim $ 40 $ 45 Jack $ 35 $ 40 我正在尝试从文本文件中读取此数据,并使用Scanner Class将信息存储到数组列表中。 任何人都可以指导我正确编写代码吗? 码 import java.io.*; import java.util.*; public class ReadStudentsGrade { public static void main(String[] args) throws IOException { ArrayList stuRec = new ArrayList(); File file = new File(“c:\\StudentGrade.txt”); try { Scanner scanner = new Scanner(file).useDelimiter(“$”); while (scanner.hasNextLine()) { String stuName = scanner.nextLine(); […]

为什么Arrays.toString(values).trim()会生成?

Map map = request.getParameterMap(); for (Entry entry : map.entrySet()) { String name = entry.getKey(); String[] values = entry.getValue(); String valuesStr = Arrays.toString(values).trim(); LOGGER.warn(valuesStr); 我正在尝试使用上面的代码查看请求参数值。 为什么Arrays.toString(values).trim(); 括起参数值,使它看起来像这样: [Georgio] 在没有括号的情况下获取字符串的最佳方法是什么? 如果我这样做: String valuesStr = values[0].trim(); 似乎存在丢失数组中后续值的风险。

如何在Java中连接二维数组

我有一种情况需要连接两个二维数组。 Object[][] getMergedResults() { Object[][] a1 = getDataFromSource1(); Object[][] a2 = getDataFromSource2(); // I can guarantee that the second dimension of a1 and a2 are the same // as I have some control over the two getDataFromSourceX() methods // concat the two arrays List result = new ArrayList(); for(Object[] entry: a1) { result.add(entry); } for(Object[] […]

如何从mongoDB数组中返回匹配的元素

我一直在寻找这个问题一周,我无法理解为什么它仍然无效…… 我有这个对象到我的MongoDB数据库: { produc: [ { cod_prod: “0001”, description: “Ordenador”, price: 400, current_stock: 3, min_stock: 1, cod_zone: “08850” }, { cod_prod: “0002”, description: “Secador”, price: 30, current_stock: 10, min_stock: 2, cod_zone: “08870” }, { cod_prod: “0003”, description: “Portatil”, price: 500, current_stock: 8, min_stock: 4, cod_zone: “08860” }, { cod_prod: “0004”, description: “Disco Duro”, price: 100, […]

用Java初始化带有流的2d数组

我有以下课程: public class MyClass{ //… public MyClass(int x, int y){ //… } } 现在,我需要使用项目初始化2d-array int rows; int cols; //initializing rows and cols MyClass[][] arr = new MyClass[rows][cols]; //how to initialize arr[x][y] with //new MyClass(x, y) with streams API 我看了一下这个例子,但它在我的情况下不起作用。 他们使用单个IntStream 问题:当然我可以使用嵌套的for循环,但我认为它现在是旧式的并且考虑不好。 那么如何应用流api并以Java8方式Java8它?

通用堆栈数组

我必须实现一个通用堆栈,但是当我尝试构建项目时,我遇到了一个我无法弄清楚的错误。 这是代码: Stack.java – >接口 package stack; public interface Stack { public boolean isEmpty(); public boolean isFull(); public void push(T x) throws StackFullException; public boolean offer(T x); public T pop() throws StackEmptyException; public T poll(); public T peek() throws StackEmptyException; public T element(); } StackArray.java – >接口的实现 package stack; public class StackArray implements Stack { […]

新String(char )和char 。toString之间的区别

Java中以下两个代码块的输出是不同的。 我想知道为什么。 private String sortChars(String s){ char[] arr = s.toCharArray(); //creating new char[] Arrays.sort(arr); //sorting that array return new String(arr); } 这个返回一个带有排序字符的字符串。 private String sortChars(String s){ char[] arr = s.toCharArray(); //creating new char[] Arrays.sort(arr); //sorting that array return arr.toString(); } 抱歉。 我的错! 用来比较两个字符串。 输出到第二个字符串看起来像许多人建议的那样 – [C @ 2e0ece65 谢谢!