小编Arm*_*ada的帖子

如果找不到Java拆分中的字符串,该怎么办?

    String incomingNumbers[ ] = writtenNumber.split("\\-");
Run Code Online (Sandbox Code Playgroud)

该程序接受自然语言编号,如三十二或五.
那么如果输入五个,那我的incomingNumbers数组中有什么东西?

java string split

26
推荐指数
1
解决办法
3万
查看次数

在Java中,如何在数组中存储大数字?

在Java中,我如何在数组中存储数字,我的意思是真正的长数字,例如高达1万亿,所以我可以访问它们并用文字打印它们是什么?

java arrays

4
推荐指数
1
解决办法
1776
查看次数

Eclipse不接受集合排序

    import java.io.BufferedReader;
    import java.util.Collections;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Comparator;
    import java.util.Date;
    import java.util.List;
    import com.javaranch.common.TextFileIn;

    public class SortNames 
    {
        public static class CelebrityNamesFile
        {
            public String firstName;
            public String lastName;

            public static class CompareLastName implements Comparator< CelebrityNamesFile >
            {
                @Override
                public int compare( CelebrityNamesFile o1,  CelebrityNamesFile o2 )
                {
                    return o2.lastName.compareTo( o1.lastName );
                }
            }

        public static void main( String[ ] args ) throws IOException
        {

            ArrayList< CelebrityNamesFile > myCelebrityList;
            myCelebrityList = new …
Run Code Online (Sandbox Code Playgroud)

java sorting collections comparator

4
推荐指数
1
解决办法
2万
查看次数

Java,我如何在main之外创建一个哈希映射,但在main或其他方法中引用它

Java,我如何在main之外创建一个哈希映射但在main或其他方法中引用它引入java.util.*;

import java.util.Map.Entry;

// Create a hash map 

        HashMap<String, Double> hm = new HashMap<String, Double>();

// Put elements into the map

        hm.put("John Doe", new Double(3434.34)); 
        hm.put("Tom Smith", new Double(123.22)); 
        hm.put("Jane Baker", new Double(1378.00)); 
        hm.put("Todd Hall", new Double(99.22)); 
        hm.put("Ralph Smith", new Double(-19.08));

class HashMapDemo 
{ 

    public static void main(String args[])
    { 
        // Get a set of the entries

        Set<Entry< String, Double> > set = hm.entrySet();

        // Get an iterator

        Iterator<Entry< String, Double> > i = set.iterator();

        // Display elements

        while(i.hasNext())
        { …
Run Code Online (Sandbox Code Playgroud)

java

2
推荐指数
1
解决办法
3825
查看次数

我如何检查空指针异常

这是代码

private static HashMap naturalNumbers = new HashMap();

static
{
    naturalNumbers.put("zero", new Integer( 0 ) );
    naturalNumbers.put("one", new Integer( 1 ) );
    naturalNumbers.put("two", new Integer( 2 ) );
    naturalNumbers.put("three", new Integer( 3 ) );
}

private static int findANumber( String partOfaNumber ) throws Exception
{
int multiplicand = 0;  
multiplicand += (Integer)naturalNumbers.get( partOfaNumber );
Run Code Online (Sandbox Code Playgroud)

如果"get"返回null,我该如何检查?

我试过了:

if ( (Integer)naturalNumbers == null )
    {
        throw new Exception( "Number not found" );
    }
 return multiplicand;
}
Run Code Online (Sandbox Code Playgroud)

但IDE甚至不接受它:无法从HashMap转换为Integer.

java hashmap nullpointerexception

1
推荐指数
1
解决办法
2629
查看次数

Java,Eclipse不接受自定义异常

Eclipse抱怨我的catch声明如下

public class NaturalLanguageMultiply
{
    public class WrongMultiplierException extends Exception
    {

    }

    private static int toInt( String number ) throws WrongMultiplierException 
    {
        // removed for clarity
                try
               {
                    String numberKey = scanner.next();
                    if ( numberMap.containsKey( numberKey ) )
                    {
                        multiplier += ( Integer ) numberMap.get( numberKey );
                    }
                    else
                    {
                        throw new WrongMultiplierException();
                    }
                }
Run Code Online (Sandbox Code Playgroud)

它抱怨以下捕获线:

Syntax error on tokens

                catch ( WrongMultiplierException );
                {

                }
            }
Run Code Online (Sandbox Code Playgroud)

另外,StackOverflow为什么一直在问:你的帖子没有太多的上下文来解释代码部分; 请更清楚地解释您的情景.我在FAQ或帮助中找不到答案.

java

0
推荐指数
1
解决办法
344
查看次数

在Java中,如何解析大于int size的字符串

我有一个大于2,147,483,647的字符串,我需要解析它.Integer.parseInt不会执行它们,它会抛出异常.

java parsing

-2
推荐指数
1
解决办法
3285
查看次数